********************************************************************************
** 	TITLE:		gb2010_bes_contact_networks		                              **
**  AUTHOR:	    Philippe Mongrain                                             **
**	DATA:       2010BES					                                      **
**	DATE:		October 2022 					                              **	
**	VERSION:	Stata 16					                                  **
********************************************************************************

* Version control

version 16.0

* Open log file

capture log close
log using "gb2010_bes_contact_networks", replace

* Open dataset

use "2010BES.dta", clear


***********************
** DISTRICT OUTCOMES **
***********************

* Clean district names

gen district_name = subinstr(tconstit, `"""',  "", .)
replace district_name = subinstr(district_name, `" Boro Const"',  "", .)
replace district_name = subinstr(district_name, `" Burgh Const"',  "", .)
replace district_name = subinstr(district_name, `" Co Const"',  "", .)
replace district_name = subinstr(district_name, `" Co Cons"',  "", .)
replace district_name = subinstr(district_name, `"."',  "", .)
replace district_name = upper(district_name)

encode district_name, gen(district_code)

* Note: 1 = Conservative, 2 = Labour, 3 = Liberal Democrats, 4 = SNP, 5 = Plaid Cymru, 6 = UKIP, 7 = Greens
							
gen district_outcome = .

replace district_outcome = 1 if district_name == "ALDERSHOT"
replace district_outcome = 1 if district_name == "ALDRIDGE-BROWNHILLS"
replace district_outcome = 1 if district_name == "ALTRINCHAM AND SALE WEST"
replace district_outcome = 1 if district_name == "AMBER VALLEY"
replace district_outcome = 1 if district_name == "ARUNDEL AND SOUTH DOWNS"
replace district_outcome = 2 if district_name == "ASHFIELD"
replace district_outcome = 1 if district_name == "ASHFORD"
replace district_outcome = 2 if district_name == "ASHTON-UNDER-LYNE"
replace district_outcome = 1 if district_name == "AYLESBURY"
replace district_outcome = 1 if district_name == "BANBURY"
replace district_outcome = 2 if district_name == "BARKING"
replace district_outcome = 2 if district_name == "BARNSLEY CENTRAL"
replace district_outcome = 2 if district_name == "BARNSLEY EAST"
replace district_outcome = 2 if district_name == "BARROW AND FURNESS"
replace district_outcome = 1 if district_name == "BASILDON AND BILLERICAY"
replace district_outcome = 1 if district_name == "BASINGSTOKE"
replace district_outcome = 2 if district_name == "BASSETLAW"
replace district_outcome = 3 if district_name == "BATH"
replace district_outcome = 2 if district_name == "BATLEY AND SPEN"
replace district_outcome = 1 if district_name == "BATTERSEA"
replace district_outcome = 1 if district_name == "BEACONSFIELD"
replace district_outcome = 1 if district_name == "BECKENHAM"
replace district_outcome = 1 if district_name == "BEDFORD"
replace district_outcome = 3 if district_name == "BERMONDSEY AND OLD SOUTHWARK"
replace district_outcome = 3 if district_name == "BERWICK-UPON-TWEED"
replace district_outcome = 2 if district_name == "BETHNAL GREEN AND BOW"
replace district_outcome = 1 if district_name == "BEVERLEY AND HOLDERNESS"
replace district_outcome = 1 if district_name == "BEXHILL AND BATTLE"
replace district_outcome = 1 if district_name == "BEXLEYHEATH AND CRAYFORD"
replace district_outcome = 2 if district_name == "BIRKENHEAD"
replace district_outcome = 2 if district_name == "BIRMINGHAM, EDGBASTON"
replace district_outcome = 2 if district_name == "BIRMINGHAM, ERDINGTON"
replace district_outcome = 2 if district_name == "BIRMINGHAM, HALL GREEN"
replace district_outcome = 2 if district_name == "BIRMINGHAM, HODGE HILL"
replace district_outcome = 2 if district_name == "BIRMINGHAM, LADYWOOD"
replace district_outcome = 2 if district_name == "BIRMINGHAM, NORTHFIELD"
replace district_outcome = 2 if district_name == "BIRMINGHAM, PERRY BARR"
replace district_outcome = 2 if district_name == "BIRMINGHAM, SELLY OAK"
replace district_outcome = 3 if district_name == "BIRMINGHAM, YARDLEY"
replace district_outcome = 2 if district_name == "BISHOP AUCKLAND"
replace district_outcome = 2 if district_name == "BLACKBURN"
replace district_outcome = 2 if district_name == "BLACKLEY AND BROUGHTON"
replace district_outcome = 1 if district_name == "BLACKPOOL NORTH AND CLEVELEYS"
replace district_outcome = 2 if district_name == "BLACKPOOL SOUTH"
replace district_outcome = 2 if district_name == "BLAYDON"
replace district_outcome = 2 if district_name == "BLYTH VALLEY"
replace district_outcome = 1 if district_name == "BOGNOR REGIS AND LITTLEHAMPTON"
replace district_outcome = 2 if district_name == "BOLSOVER"
replace district_outcome = 2 if district_name == "BOLTON NORTH EAST"
replace district_outcome = 2 if district_name == "BOLTON SOUTH EAST"
replace district_outcome = 2 if district_name == "BOLTON WEST"
replace district_outcome = 2 if district_name == "BOOTLE"
replace district_outcome = 1 if district_name == "BOSTON AND SKEGNESS"
replace district_outcome = 1 if district_name == "BOSWORTH"
replace district_outcome = 1 if district_name == "BOURNEMOUTH EAST"
replace district_outcome = 1 if district_name == "BOURNEMOUTH WEST"
replace district_outcome = 1 if district_name == "BRACKNELL"
replace district_outcome = 3 if district_name == "BRADFORD EAST"
replace district_outcome = 2 if district_name == "BRADFORD SOUTH"
replace district_outcome = 2 if district_name == "BRADFORD WEST"
replace district_outcome = 1 if district_name == "BRAINTREE"
replace district_outcome = 3 if district_name == "BRENT CENTRAL"
replace district_outcome = 2 if district_name == "BRENT NORTH"
replace district_outcome = 1 if district_name == "BRENTFORD AND ISLEWORTH"
replace district_outcome = 1 if district_name == "BRENTWOOD AND ONGAR"
replace district_outcome = 1 if district_name == "BRIDGWATER AND WEST SOMERSET"
replace district_outcome = 1 if district_name == "BRIGG AND GOOLE"
replace district_outcome = 1 if district_name == "BRIGHTON, KEMPTOWN"
replace district_outcome = 7 if district_name == "BRIGHTON, PAVILION"
replace district_outcome = 2 if district_name == "BRISTOL EAST"
replace district_outcome = 1 if district_name == "BRISTOL NORTH WEST"
replace district_outcome = 2 if district_name == "BRISTOL SOUTH"
replace district_outcome = 3 if district_name == "BRISTOL WEST"
replace district_outcome = 1 if district_name == "BROADLAND"
replace district_outcome = 1 if district_name == "BROMLEY AND CHISLEHURST"
replace district_outcome = 1 if district_name == "BROMSGROVE"
replace district_outcome = 1 if district_name == "BROXBOURNE"
replace district_outcome = 1 if district_name == "BROXTOWE"
replace district_outcome = 9 if district_name == "BUCKINGHAM"
replace district_outcome = 3 if district_name == "BURNLEY"
replace district_outcome = 1 if district_name == "BURTON"
replace district_outcome = 1 if district_name == "BURY NORTH"
replace district_outcome = 2 if district_name == "BURY SOUTH"
replace district_outcome = 1 if district_name == "BURY ST EDMUNDS"
replace district_outcome = 1 if district_name == "CALDER VALLEY"
replace district_outcome = 2 if district_name == "CAMBERWELL AND PECKHAM"
replace district_outcome = 1 if district_name == "CAMBORNE AND REDRUTH"
replace district_outcome = 3 if district_name == "CAMBRIDGE"
replace district_outcome = 1 if district_name == "CANNOCK CHASE"
replace district_outcome = 1 if district_name == "CANTERBURY"
replace district_outcome = 1 if district_name == "CARLISLE"
replace district_outcome = 3 if district_name == "CARSHALTON AND WALLINGTON"
replace district_outcome = 1 if district_name == "CASTLE POINT"
replace district_outcome = 1 if district_name == "CENTRAL DEVON"
replace district_outcome = 1 if district_name == "CENTRAL SUFFOLK AND NORTH IPSWICH"
replace district_outcome = 1 if district_name == "CHARNWOOD"
replace district_outcome = 1 if district_name == "CHATHAM AND AYLESFORD"
replace district_outcome = 3 if district_name == "CHEADLE"
replace district_outcome = 1 if district_name == "CHELMSFORD"
replace district_outcome = 1 if district_name == "CHELSEA AND FULHAM"
replace district_outcome = 3 if district_name == "CHELTENHAM"
replace district_outcome = 1 if district_name == "CHESHAM AND AMERSHAM"
replace district_outcome = 2 if district_name == "CHESTERFIELD"
replace district_outcome = 1 if district_name == "CHICHESTER"
replace district_outcome = 1 if district_name == "CHINGFORD AND WOODFORD GREEN"
replace district_outcome = 3 if district_name == "CHIPPENHAM"
replace district_outcome = 1 if district_name == "CHIPPING BARNET"
replace district_outcome = 2 if district_name == "CHORLEY"
replace district_outcome = 1 if district_name == "CHRISTCHURCH"
replace district_outcome = 1 if district_name == "CITIES OF LONDON AND WESTMINSTER"
replace district_outcome = 1 if district_name == "CITY OF CHESTER"
replace district_outcome = 2 if district_name == "CITY OF DURHAM"
replace district_outcome = 1 if district_name == "CLACTON"
replace district_outcome = 1 if district_name == "CLEETHORPES"
replace district_outcome = 3 if district_name == "COLCHESTER"
replace district_outcome = 1 if district_name == "COLNE VALLEY"
replace district_outcome = 1 if district_name == "CONGLETON"
replace district_outcome = 2 if district_name == "COPELAND"
replace district_outcome = 1 if district_name == "CORBY"
replace district_outcome = 2 if district_name == "COVENTRY NORTH EAST"
replace district_outcome = 2 if district_name == "COVENTRY NORTH WEST"
replace district_outcome = 2 if district_name == "COVENTRY SOUTH"
replace district_outcome = 1 if district_name == "CRAWLEY"
replace district_outcome = 1 if district_name == "CREWE AND NANTWICH"
replace district_outcome = 1 if district_name == "CROYDON CENTRAL"
replace district_outcome = 2 if district_name == "CROYDON NORTH"
replace district_outcome = 1 if district_name == "CROYDON SOUTH"
replace district_outcome = 2 if district_name == "DAGENHAM AND RAINHAM"
replace district_outcome = 2 if district_name == "DARLINGTON"
replace district_outcome = 1 if district_name == "DARTFORD"
replace district_outcome = 1 if district_name == "DAVENTRY"
replace district_outcome = 2 if district_name == "DENTON AND REDDISH"
replace district_outcome = 2 if district_name == "DERBY NORTH"
replace district_outcome = 2 if district_name == "DERBY SOUTH"
replace district_outcome = 1 if district_name == "DERBYSHIRE DALES"
replace district_outcome = 1 if district_name == "DEVIZES"
replace district_outcome = 1 if district_name == "DEWSBURY"
replace district_outcome = 2 if district_name == "DON VALLEY"
replace district_outcome = 2 if district_name == "DONCASTER CENTRAL"
replace district_outcome = 2 if district_name == "DONCASTER NORTH"
replace district_outcome = 1 if district_name == "DOVER"
replace district_outcome = 2 if district_name == "DUDLEY NORTH"
replace district_outcome = 1 if district_name == "DUDLEY SOUTH"
replace district_outcome = 2 if district_name == "DULWICH AND WEST NORWOOD"
replace district_outcome = 1 if district_name == "EALING CENTRAL AND ACTON"
replace district_outcome = 2 if district_name == "EALING NORTH"
replace district_outcome = 2 if district_name == "EALING, SOUTHALL"
replace district_outcome = 2 if district_name == "EASINGTON"
replace district_outcome = 1 if district_name == "EAST DEVON"
replace district_outcome = 2 if district_name == "EAST HAM"
replace district_outcome = 1 if district_name == "EAST HAMPSHIRE"
replace district_outcome = 1 if district_name == "EAST SURREY"
replace district_outcome = 1 if district_name == "EAST WORTHING AND SHOREHAM"
replace district_outcome = 1 if district_name == "EAST YORKSHIRE"
replace district_outcome = 3 if district_name == "EASTBOURNE"
replace district_outcome = 3 if district_name == "EASTLEIGH"
replace district_outcome = 1 if district_name == "EDDISBURY"
replace district_outcome = 2 if district_name == "EDMONTON"
replace district_outcome = 2 if district_name == "ELLESMERE PORT AND NESTON"
replace district_outcome = 1 if district_name == "ELMET AND ROTHWELL"
replace district_outcome = 2 if district_name == "ELTHAM"
replace district_outcome = 1 if district_name == "ENFIELD NORTH"
replace district_outcome = 1 if district_name == "ENFIELD, SOUTHGATE"
replace district_outcome = 1 if district_name == "EPPING FOREST"
replace district_outcome = 1 if district_name == "EPSOM AND EWELL"
replace district_outcome = 1 if district_name == "EREWASH"
replace district_outcome = 2 if district_name == "ERITH AND THAMESMEAD"
replace district_outcome = 1 if district_name == "ESHER AND WALTON"
replace district_outcome = 2 if district_name == "EXETER"
replace district_outcome = 1 if district_name == "FAREHAM"
replace district_outcome = 1 if district_name == "FAVERSHAM AND MID KENT"
replace district_outcome = 2 if district_name == "FELTHAM AND HESTON"
replace district_outcome = 1 if district_name == "FILTON AND BRADLEY STOKE"
replace district_outcome = 1 if district_name == "FINCHLEY AND GOLDERS GREEN"
replace district_outcome = 1 if district_name == "FOLKESTONE AND HYTHE"
replace district_outcome = 1 if district_name == "FOREST OF DEAN"
replace district_outcome = 1 if district_name == "FYLDE"
replace district_outcome = 1 if district_name == "GAINSBOROUGH"
replace district_outcome = 2 if district_name == "GARSTON AND HALEWOOD"
replace district_outcome = 2 if district_name == "GATESHEAD"
replace district_outcome = 2 if district_name == "GEDLING"
replace district_outcome = 1 if district_name == "GILLINGHAM AND RAINHAM"
replace district_outcome = 1 if district_name == "GLOUCESTER"
replace district_outcome = 1 if district_name == "GOSPORT"
replace district_outcome = 1 if district_name == "GRANTHAM AND STAMFORD"
replace district_outcome = 1 if district_name == "GRAVESHAM"
replace district_outcome = 2 if district_name == "GREAT GRIMSBY"
replace district_outcome = 1 if district_name == "GREAT YARMOUTH"
replace district_outcome = 2 if district_name == "GREENWICH AND WOOLWICH"
replace district_outcome = 1 if district_name == "GUILDFORD"
replace district_outcome = 2 if district_name == "HACKNEY NORTH AND STOKE NEWINGTON"
replace district_outcome = 2 if district_name == "HACKNEY SOUTH AND SHOREDITCH"
replace district_outcome = 1 if district_name == "HALESOWEN AND ROWLEY REGIS"
replace district_outcome = 2 if district_name == "HALIFAX"
replace district_outcome = 1 if district_name == "HALTEMPRICE AND HOWDEN"
replace district_outcome = 2 if district_name == "HALTON"
replace district_outcome = 2 if district_name == "HAMMERSMITH"
replace district_outcome = 2 if district_name == "HAMPSTEAD AND KILBURN"
replace district_outcome = 1 if district_name == "HARBOROUGH"
replace district_outcome = 1 if district_name == "HARLOW"
replace district_outcome = 1 if district_name == "HARROGATE AND KNARESBOROUGH"
replace district_outcome = 1 if district_name == "HARROW EAST"
replace district_outcome = 2 if district_name == "HARROW WEST"
replace district_outcome = 2 if district_name == "HARTLEPOOL"
replace district_outcome = 1 if district_name == "HARWICH AND NORTH ESSEX"
replace district_outcome = 1 if district_name == "HASTINGS AND RYE"
replace district_outcome = 1 if district_name == "HAVANT"
replace district_outcome = 2 if district_name == "HAYES AND HARLINGTON"
replace district_outcome = 3 if district_name == "HAZEL GROVE"
replace district_outcome = 1 if district_name == "HEMEL HEMPSTEAD"
replace district_outcome = 2 if district_name == "HEMSWORTH"
replace district_outcome = 1 if district_name == "HENDON"
replace district_outcome = 1 if district_name == "HENLEY"
replace district_outcome = 1 if district_name == "HEREFORD AND SOUTH HEREFORDSHIRE"
replace district_outcome = 1 if district_name == "HERTFORD AND STORTFORD"
replace district_outcome = 1 if district_name == "HERTSMERE"
replace district_outcome = 1 if district_name == "HEXHAM"
replace district_outcome = 2 if district_name == "HEYWOOD AND MIDDLETON"
replace district_outcome = 1 if district_name == "HIGH PEAK"
replace district_outcome = 1 if district_name == "HITCHIN AND HARPENDEN"
replace district_outcome = 2 if district_name == "HOLBORN AND ST PANCRAS"
replace district_outcome = 1 if district_name == "HORNCHURCH AND UPMINSTER"
replace district_outcome = 3 if district_name == "HORNSEY AND WOOD GREEN"
replace district_outcome = 1 if district_name == "HORSHAM"
replace district_outcome = 2 if district_name == "HOUGHTON AND SUNDERLAND SOUTH"
replace district_outcome = 1 if district_name == "HOVE"
replace district_outcome = 2 if district_name == "HUDDERSFIELD"
replace district_outcome = 1 if district_name == "HUNTINGDON"
replace district_outcome = 2 if district_name == "HYNDBURN"
replace district_outcome = 1 if district_name == "ILFORD NORTH"
replace district_outcome = 2 if district_name == "ILFORD SOUTH"
replace district_outcome = 1 if district_name == "IPSWICH"
replace district_outcome = 1 if district_name == "ISLE OF WIGHT"
replace district_outcome = 2 if district_name == "ISLINGTON NORTH"
replace district_outcome = 2 if district_name == "ISLINGTON SOUTH AND FINSBURY"
replace district_outcome = 2 if district_name == "JARROW"
replace district_outcome = 1 if district_name == "KEIGHLEY"
replace district_outcome = 1 if district_name == "KENILWORTH AND SOUTHAM"
replace district_outcome = 1 if district_name == "KENSINGTON"
replace district_outcome = 1 if district_name == "KETTERING"
replace district_outcome = 3 if district_name == "KINGSTON AND SURBITON"
replace district_outcome = 2 if district_name == "KINGSTON UPON HULL EAST"
replace district_outcome = 2 if district_name == "KINGSTON UPON HULL NORTH"
replace district_outcome = 2 if district_name == "KINGSTON UPON HULL WEST AND HESSLE"
replace district_outcome = 1 if district_name == "KINGSWOOD"
replace district_outcome = 2 if district_name == "KNOWSLEY"
replace district_outcome = 1 if district_name == "LANCASTER AND FLEETWOOD"
replace district_outcome = 2 if district_name == "LEEDS CENTRAL"
replace district_outcome = 2 if district_name == "LEEDS EAST"
replace district_outcome = 2 if district_name == "LEEDS NORTH EAST"
replace district_outcome = 3 if district_name == "LEEDS NORTH WEST"
replace district_outcome = 2 if district_name == "LEEDS WEST"
replace district_outcome = 2 if district_name == "LEICESTER EAST"
replace district_outcome = 2 if district_name == "LEICESTER SOUTH"
replace district_outcome = 2 if district_name == "LEICESTER WEST"
replace district_outcome = 2 if district_name == "LEIGH"
replace district_outcome = 3 if district_name == "LEWES"
replace district_outcome = 2 if district_name == "LEWISHAM EAST"
replace district_outcome = 2 if district_name == "LEWISHAM WEST AND PENGE"
replace district_outcome = 2 if district_name == "LEWISHAM, DEPTFORD"
replace district_outcome = 2 if district_name == "LEYTON AND WANSTEAD"
replace district_outcome = 1 if district_name == "LICHFIELD"
replace district_outcome = 1 if district_name == "LINCOLN"
replace district_outcome = 2 if district_name == "LIVERPOOL, RIVERSIDE"
replace district_outcome = 2 if district_name == "LIVERPOOL, WALTON"
replace district_outcome = 2 if district_name == "LIVERPOOL, WAVERTREE"
replace district_outcome = 2 if district_name == "LIVERPOOL, WEST DERBY"
replace district_outcome = 1 if district_name == "LOUGHBOROUGH"
replace district_outcome = 1 if district_name == "LOUTH AND HORNCASTLE"
replace district_outcome = 1 if district_name == "LUDLOW"
replace district_outcome = 2 if district_name == "LUTON NORTH"
replace district_outcome = 2 if district_name == "LUTON SOUTH"
replace district_outcome = 1 if district_name == "MACCLESFIELD"
replace district_outcome = 1 if district_name == "MAIDENHEAD"
replace district_outcome = 1 if district_name == "MAIDSTONE AND THE WEALD"
replace district_outcome = 2 if district_name == "MAKERFIELD"
replace district_outcome = 1 if district_name == "MALDON"
replace district_outcome = 2 if district_name == "MANCHESTER CENTRAL"
replace district_outcome = 2 if district_name == "MANCHESTER, GORTON"
replace district_outcome = 3 if district_name == "MANCHESTER, WITHINGTON"
replace district_outcome = 2 if district_name == "MANSFIELD"
replace district_outcome = 1 if district_name == "MEON VALLEY"
replace district_outcome = 1 if district_name == "MERIDEN"
replace district_outcome = 1 if district_name == "MID BEDFORDSHIRE"
replace district_outcome = 1 if district_name == "MID DERBYSHIRE"
replace district_outcome = 3 if district_name == "MID DORSET AND NORTH POOLE"
replace district_outcome = 1 if district_name == "MID NORFOLK"
replace district_outcome = 1 if district_name == "MID SUSSEX"
replace district_outcome = 1 if district_name == "MID WORCESTERSHIRE"
replace district_outcome = 2 if district_name == "MIDDLESBROUGH"
replace district_outcome = 2 if district_name == "MIDDLESBROUGH SOUTH AND EAST CLEVELAND"
replace district_outcome = 1 if district_name == "MILTON KEYNES NORTH"
replace district_outcome = 1 if district_name == "MILTON KEYNES SOUTH"
replace district_outcome = 2 if district_name == "MITCHAM AND MORDEN"
replace district_outcome = 1 if district_name == "MOLE VALLEY"
replace district_outcome = 1 if district_name == "MORECAMBE AND LUNESDALE"
replace district_outcome = 2 if district_name == "MORLEY AND OUTWOOD"
replace district_outcome = 1 if district_name == "NEW FOREST EAST"
replace district_outcome = 1 if district_name == "NEW FOREST WEST"
replace district_outcome = 1 if district_name == "NEWARK"
replace district_outcome = 1 if district_name == "NEWBURY"
replace district_outcome = 2 if district_name == "NEWCASTLE UPON TYNE CENTRAL"
replace district_outcome = 2 if district_name == "NEWCASTLE UPON TYNE EAST"
replace district_outcome = 2 if district_name == "NEWCASTLE UPON TYNE NORTH"
replace district_outcome = 2 if district_name == "NEWCASTLE-UNDER-LYME"
replace district_outcome = 1 if district_name == "NEWTON ABBOT"
replace district_outcome = 2 if district_name == "NORMANTON, PONTEFRACT AND CASTLEFORD"
replace district_outcome = 3 if district_name == "NORTH CORNWALL"
replace district_outcome = 3 if district_name == "NORTH DEVON"
replace district_outcome = 1 if district_name == "NORTH DORSET"
replace district_outcome = 2 if district_name == "NORTH DURHAM"
replace district_outcome = 1 if district_name == "NORTH EAST BEDFORDSHIRE"
replace district_outcome = 1 if district_name == "NORTH EAST CAMBRIDGESHIRE"
replace district_outcome = 2 if district_name == "NORTH EAST DERBYSHIRE"
replace district_outcome = 1 if district_name == "NORTH EAST HAMPSHIRE"
replace district_outcome = 1 if district_name == "NORTH EAST HERTFORDSHIRE"
replace district_outcome = 1 if district_name == "NORTH EAST SOMERSET"
replace district_outcome = 1 if district_name == "NORTH HEREFORDSHIRE"
replace district_outcome = 3 if district_name == "NORTH NORFOLK"
replace district_outcome = 1 if district_name == "NORTH SHROPSHIRE"
replace district_outcome = 1 if district_name == "NORTH SOMERSET"
replace district_outcome = 1 if district_name == "NORTH SWINDON"
replace district_outcome = 1 if district_name == "NORTH THANET"
replace district_outcome = 2 if district_name == "NORTH TYNESIDE"
replace district_outcome = 1 if district_name == "NORTH WARWICKSHIRE"
replace district_outcome = 1 if district_name == "NORTH WEST CAMBRIDGESHIRE"
replace district_outcome = 2 if district_name == "NORTH WEST DURHAM"
replace district_outcome = 1 if district_name == "NORTH WEST HAMPSHIRE"
replace district_outcome = 1 if district_name == "NORTH WEST LEICESTERSHIRE"
replace district_outcome = 1 if district_name == "NORTH WEST NORFOLK"
replace district_outcome = 1 if district_name == "NORTH WILTSHIRE"
replace district_outcome = 1 if district_name == "NORTHAMPTON NORTH"
replace district_outcome = 1 if district_name == "NORTHAMPTON SOUTH"
replace district_outcome = 1 if district_name == "NORWICH NORTH"
replace district_outcome = 3 if district_name == "NORWICH SOUTH"
replace district_outcome = 2 if district_name == "NOTTINGHAM EAST"
replace district_outcome = 2 if district_name == "NOTTINGHAM NORTH"
replace district_outcome = 2 if district_name == "NOTTINGHAM SOUTH"
replace district_outcome = 1 if district_name == "NUNEATON"
replace district_outcome = 1 if district_name == "OLD BEXLEY AND SIDCUP"
replace district_outcome = 2 if district_name == "OLDHAM EAST AND SADDLEWORTH"
replace district_outcome = 2 if district_name == "OLDHAM WEST AND ROYTON"
replace district_outcome = 1 if district_name == "ORPINGTON"
replace district_outcome = 2 if district_name == "OXFORD EAST"
replace district_outcome = 1 if district_name == "OXFORD WEST AND ABINGDON"
replace district_outcome = 1 if district_name == "PENDLE"
replace district_outcome = 2 if district_name == "PENISTONE AND STOCKSBRIDGE"
replace district_outcome = 1 if district_name == "PENRITH AND THE BORDER"
replace district_outcome = 1 if district_name == "PETERBOROUGH"
replace district_outcome = 2 if district_name == "PLYMOUTH, MOOR VIEW"
replace district_outcome = 1 if district_name == "PLYMOUTH, SUTTON AND DEVONPORT"
replace district_outcome = 1 if district_name == "POOLE"
replace district_outcome = 2 if district_name == "POPLAR AND LIMEHOUSE"
replace district_outcome = 1 if district_name == "PORTSMOUTH NORTH"
replace district_outcome = 3 if district_name == "PORTSMOUTH SOUTH"
replace district_outcome = 2 if district_name == "PRESTON"
replace district_outcome = 1 if district_name == "PUDSEY"
replace district_outcome = 1 if district_name == "PUTNEY"
replace district_outcome = 1 if district_name == "RAYLEIGH AND WICKFORD"
replace district_outcome = 1 if district_name == "READING EAST"
replace district_outcome = 1 if district_name == "READING WEST"
replace district_outcome = 3 if district_name == "REDCAR"
replace district_outcome = 1 if district_name == "REDDITCH"
replace district_outcome = 1 if district_name == "REIGATE"
replace district_outcome = 1 if district_name == "RIBBLE VALLEY"
replace district_outcome = 1 if district_name == "RICHMOND (YORKS)"
replace district_outcome = 1 if district_name == "RICHMOND PARK"
replace district_outcome = 2 if district_name == "ROCHDALE"
replace district_outcome = 1 if district_name == "ROCHESTER AND STROOD"
replace district_outcome = 1 if district_name == "ROCHFORD AND SOUTHEND EAST"
replace district_outcome = 1 if district_name == "ROMFORD"
replace district_outcome = 1 if district_name == "ROMSEY AND SOUTHAMPTON NORTH"
replace district_outcome = 1 if district_name == "ROSSENDALE AND DARWEN"
replace district_outcome = 2 if district_name == "ROTHER VALLEY"
replace district_outcome = 2 if district_name == "ROTHERHAM"
replace district_outcome = 1 if district_name == "RUGBY"
replace district_outcome = 1 if district_name == "RUISLIP, NORTHWOOD AND PINNER"
replace district_outcome = 1 if district_name == "RUNNYMEDE AND WEYBRIDGE"
replace district_outcome = 1 if district_name == "RUSHCLIFFE"
replace district_outcome = 1 if district_name == "RUTLAND AND MELTON"
replace district_outcome = 1 if district_name == "SAFFRON WALDEN"
replace district_outcome = 2 if district_name == "SALFORD AND ECCLES"
replace district_outcome = 1 if district_name == "SALISBURY"
replace district_outcome = 1 if district_name == "SCARBOROUGH AND WHITBY"
replace district_outcome = 2 if district_name == "SCUNTHORPE"
replace district_outcome = 2 if district_name == "SEDGEFIELD"
replace district_outcome = 2 if district_name == "SEFTON CENTRAL"
replace district_outcome = 1 if district_name == "SELBY AND AINSTY"
replace district_outcome = 1 if district_name == "SEVENOAKS"
replace district_outcome = 2 if district_name == "SHEFFIELD CENTRAL"
replace district_outcome = 2 if district_name == "SHEFFIELD SOUTH EAST"
replace district_outcome = 2 if district_name == "SHEFFIELD, BRIGHTSIDE AND HILLSBOROUGH"
replace district_outcome = 3 if district_name == "SHEFFIELD, HALLAM"
replace district_outcome = 2 if district_name == "SHEFFIELD, HEELEY"
replace district_outcome = 1 if district_name == "SHERWOOD"
replace district_outcome = 1 if district_name == "SHIPLEY"
replace district_outcome = 1 if district_name == "SHREWSBURY AND ATCHAM"
replace district_outcome = 1 if district_name == "SITTINGBOURNE AND SHEPPEY"
replace district_outcome = 1 if district_name == "SKIPTON AND RIPON"
replace district_outcome = 1 if district_name == "SLEAFORD AND NORTH HYKEHAM"
replace district_outcome = 2 if district_name == "SLOUGH"
replace district_outcome = 3 if district_name == "SOLIHULL"
replace district_outcome = 3 if district_name == "SOMERTON AND FROME"
replace district_outcome = 1 if district_name == "SOUTH BASILDON AND EAST THURROCK"
replace district_outcome = 1 if district_name == "SOUTH CAMBRIDGESHIRE"
replace district_outcome = 1 if district_name == "SOUTH DERBYSHIRE"
replace district_outcome = 1 if district_name == "SOUTH DORSET"
replace district_outcome = 1 if district_name == "SOUTH EAST CAMBRIDGESHIRE"
replace district_outcome = 1 if district_name == "SOUTH EAST CORNWALL"
replace district_outcome = 1 if district_name == "SOUTH HOLLAND AND THE DEEPINGS"
replace district_outcome = 1 if district_name == "SOUTH LEICESTERSHIRE"
replace district_outcome = 1 if district_name == "SOUTH NORFOLK"
replace district_outcome = 1 if district_name == "SOUTH NORTHAMPTONSHIRE"
replace district_outcome = 1 if district_name == "SOUTH RIBBLE"
replace district_outcome = 2 if district_name == "SOUTH SHIELDS"
replace district_outcome = 1 if district_name == "SOUTH STAFFORDSHIRE"
replace district_outcome = 1 if district_name == "SOUTH SUFFOLK"
replace district_outcome = 1 if district_name == "SOUTH SWINDON"
replace district_outcome = 1 if district_name == "SOUTH THANET"
replace district_outcome = 1 if district_name == "SOUTH WEST BEDFORDSHIRE"
replace district_outcome = 1 if district_name == "SOUTH WEST DEVON"
replace district_outcome = 1 if district_name == "SOUTH WEST HERTFORDSHIRE"
replace district_outcome = 1 if district_name == "SOUTH WEST NORFOLK"
replace district_outcome = 1 if district_name == "SOUTH WEST SURREY"
replace district_outcome = 1 if district_name == "SOUTH WEST WILTSHIRE"
replace district_outcome = 2 if district_name == "SOUTHAMPTON, ITCHEN"
replace district_outcome = 2 if district_name == "SOUTHAMPTON, TEST"
replace district_outcome = 1 if district_name == "SOUTHEND WEST"
replace district_outcome = 3 if district_name == "SOUTHPORT"
replace district_outcome = 1 if district_name == "SPELTHORNE"
replace district_outcome = 1 if district_name == "ST ALBANS"
replace district_outcome = 3 if district_name == "ST AUSTELL AND NEWQUAY"
replace district_outcome = 2 if district_name == "ST HELENS NORTH"
replace district_outcome = 2 if district_name == "ST HELENS SOUTH AND WHISTON"
replace district_outcome = 3 if district_name == "ST IVES"
replace district_outcome = 1 if district_name == "STAFFORD"
replace district_outcome = 1 if district_name == "STAFFORDSHIRE MOORLANDS"
replace district_outcome = 2 if district_name == "STALYBRIDGE AND HYDE"
replace district_outcome = 1 if district_name == "STEVENAGE"
replace district_outcome = 2 if district_name == "STOCKPORT"
replace district_outcome = 2 if district_name == "STOCKTON NORTH"
replace district_outcome = 1 if district_name == "STOCKTON SOUTH"
replace district_outcome = 2 if district_name == "STOKE-ON-TRENT CENTRAL"
replace district_outcome = 2 if district_name == "STOKE-ON-TRENT NORTH"
replace district_outcome = 2 if district_name == "STOKE-ON-TRENT SOUTH"
replace district_outcome = 1 if district_name == "STONE"
replace district_outcome = 1 if district_name == "STOURBRIDGE"
replace district_outcome = 1 if district_name == "STRATFORD-ON-AVON"
replace district_outcome = 2 if district_name == "STREATHAM"
replace district_outcome = 2 if district_name == "STRETFORD AND URMSTON"
replace district_outcome = 1 if district_name == "STROUD"
replace district_outcome = 1 if district_name == "SUFFOLK COASTAL"
replace district_outcome = 2 if district_name == "SUNDERLAND CENTRAL"
replace district_outcome = 1 if district_name == "SURREY HEATH"
replace district_outcome = 3 if district_name == "SUTTON AND CHEAM"
replace district_outcome = 1 if district_name == "SUTTON COLDFIELD"
replace district_outcome = 1 if district_name == "TAMWORTH"
replace district_outcome = 1 if district_name == "TATTON"
replace district_outcome = 3 if district_name == "TAUNTON DEANE"
replace district_outcome = 2 if district_name == "TELFORD"
replace district_outcome = 1 if district_name == "TEWKESBURY"
replace district_outcome = 1 if district_name == "THE COTSWOLDS"
replace district_outcome = 1 if district_name == "THE WREKIN"
replace district_outcome = 1 if district_name == "THIRSK AND MALTON"
replace district_outcome = 3 if district_name == "THORNBURY AND YATE"
replace district_outcome = 1 if district_name == "THURROCK"
replace district_outcome = 1 if district_name == "TIVERTON AND HONITON"
replace district_outcome = 1 if district_name == "TONBRIDGE AND MALLING"
replace district_outcome = 2 if district_name == "TOOTING"
replace district_outcome = 3 if district_name == "TORBAY"
replace district_outcome = 1 if district_name == "TORRIDGE AND WEST DEVON"
replace district_outcome = 1 if district_name == "TOTNES"
replace district_outcome = 2 if district_name == "TOTTENHAM"
replace district_outcome = 1 if district_name == "TRURO AND FALMOUTH"
replace district_outcome = 1 if district_name == "TUNBRIDGE WELLS"
replace district_outcome = 3 if district_name == "TWICKENHAM"
replace district_outcome = 2 if district_name == "TYNEMOUTH"
replace district_outcome = 1 if district_name == "UXBRIDGE AND SOUTH RUISLIP"
replace district_outcome = 2 if district_name == "VAUXHALL"
replace district_outcome = 2 if district_name == "WAKEFIELD"
replace district_outcome = 2 if district_name == "WALLASEY"
replace district_outcome = 2 if district_name == "WALSALL NORTH"
replace district_outcome = 2 if district_name == "WALSALL SOUTH"
replace district_outcome = 2 if district_name == "WALTHAMSTOW"
replace district_outcome = 2 if district_name == "WANSBECK"
replace district_outcome = 1 if district_name == "WANTAGE"
replace district_outcome = 2 if district_name == "WARLEY"
replace district_outcome = 2 if district_name == "WARRINGTON NORTH"
replace district_outcome = 1 if district_name == "WARRINGTON SOUTH"
replace district_outcome = 1 if district_name == "WARWICK AND LEAMINGTON"
replace district_outcome = 2 if district_name == "WASHINGTON AND SUNDERLAND WEST"
replace district_outcome = 1 if district_name == "WATFORD"
replace district_outcome = 1 if district_name == "WAVENEY"
replace district_outcome = 1 if district_name == "WEALDEN"
replace district_outcome = 1 if district_name == "WEAVER VALE"
replace district_outcome = 1 if district_name == "WELLINGBOROUGH"
replace district_outcome = 3 if district_name == "WELLS"
replace district_outcome = 1 if district_name == "WELWYN HATFIELD"
replace district_outcome = 2 if district_name == "WENTWORTH AND DEARNE"
replace district_outcome = 2 if district_name == "WEST BROMWICH EAST"
replace district_outcome = 2 if district_name == "WEST BROMWICH WEST"
replace district_outcome = 1 if district_name == "WEST DORSET"
replace district_outcome = 2 if district_name == "WEST HAM"
replace district_outcome = 2 if district_name == "WEST LANCASHIRE"
replace district_outcome = 1 if district_name == "WEST SUFFOLK"
replace district_outcome = 1 if district_name == "WEST WORCESTERSHIRE"
replace district_outcome = 2 if district_name == "WESTMINSTER NORTH"
replace district_outcome = 3 if district_name == "WESTMORLAND AND LONSDALE"
replace district_outcome = 1 if district_name == "WESTON-SUPER-MARE"
replace district_outcome = 2 if district_name == "WIGAN"
replace district_outcome = 1 if district_name == "WIMBLEDON"
replace district_outcome = 1 if district_name == "WINCHESTER"
replace district_outcome = 1 if district_name == "WINDSOR"
replace district_outcome = 2 if district_name == "WIRRAL SOUTH"
replace district_outcome = 1 if district_name == "WIRRAL WEST"
replace district_outcome = 1 if district_name == "WITHAM"
replace district_outcome = 1 if district_name == "WITNEY"
replace district_outcome = 1 if district_name == "WOKING"
replace district_outcome = 1 if district_name == "WOKINGHAM"
replace district_outcome = 2 if district_name == "WOLVERHAMPTON NORTH EAST"
replace district_outcome = 2 if district_name == "WOLVERHAMPTON SOUTH EAST"
replace district_outcome = 1 if district_name == "WOLVERHAMPTON SOUTH WEST"
replace district_outcome = 1 if district_name == "WORCESTER"
replace district_outcome = 2 if district_name == "WORKINGTON"
replace district_outcome = 2 if district_name == "WORSLEY AND ECCLES SOUTH"
replace district_outcome = 1 if district_name == "WORTHING WEST"
replace district_outcome = 1 if district_name == "WYCOMBE"
replace district_outcome = 1 if district_name == "WYRE AND PRESTON NORTH"
replace district_outcome = 1 if district_name == "WYRE FOREST"
replace district_outcome = 2 if district_name == "WYTHENSHAWE AND SALE EAST"
replace district_outcome = 3 if district_name == "YEOVIL"
replace district_outcome = 2 if district_name == "YORK CENTRAL"
replace district_outcome = 1 if district_name == "YORK OUTER"
replace district_outcome = 9 if district_name == "BELFAST EAST"
replace district_outcome = 9 if district_name == "BELFAST NORTH"
replace district_outcome = 9 if district_name == "BELFAST SOUTH"
replace district_outcome = 9 if district_name == "BELFAST WEST"
replace district_outcome = 9 if district_name == "EAST ANTRIM"
replace district_outcome = 9 if district_name == "EAST LONDONDERRY"
replace district_outcome = 9 if district_name == "FERMANAGH AND SOUTH TYRONE"
replace district_outcome = 9 if district_name == "FOYLE"
replace district_outcome = 9 if district_name == "LAGAN VALLEY"
replace district_outcome = 9 if district_name == "MID ULSTER"
replace district_outcome = 9 if district_name == "NEWRY AND ARMAGH"
replace district_outcome = 9 if district_name == "NORTH ANTRIM"
replace district_outcome = 9 if district_name == "NORTH DOWN"
replace district_outcome = 9 if district_name == "SOUTH ANTRIM"
replace district_outcome = 9 if district_name == "SOUTH DOWN"
replace district_outcome = 9 if district_name == "STRANGFORD"
replace district_outcome = 9 if district_name == "UPPER BANN"
replace district_outcome = 9 if district_name == "WEST TYRONE"
replace district_outcome = 2 if district_name == "ABERDEEN NORTH"
replace district_outcome = 2 if district_name == "ABERDEEN SOUTH"
replace district_outcome = 2 if district_name == "AIRDRIE AND SHOTTS"
replace district_outcome = 9 if district_name == "ANGUS"
replace district_outcome = 3 if district_name == "ARGYLL AND BUTE"
replace district_outcome = 2 if district_name == "AYR, CARRICK AND CUMNOCK"
replace district_outcome = 9 if district_name == "BANFF AND BUCHAN"
replace district_outcome = 3 if district_name == "BERWICKSHIRE, ROXBURGH AND SELKIRK"
replace district_outcome = 3 if district_name == "CAITHNESS, SUTHERLAND AND EASTER ROSS"
replace district_outcome = 2 if district_name == "CENTRAL AYRSHIRE"
replace district_outcome = 2 if district_name == "COATBRIDGE, CHRYSTON AND BELLSHILL"
replace district_outcome = 2 if district_name == "CUMBERNAULD, KILSYTH AND KIRKINTILLOCH EAST"
replace district_outcome = 2 if district_name == "DUMFRIES AND GALLOWAY"
replace district_outcome = 1 if district_name == "DUMFRIESSHIRE, CLYDESDALE AND TWEEDDALE"
replace district_outcome = 9 if district_name == "DUNDEE EAST"
replace district_outcome = 2 if district_name == "DUNDEE WEST"
replace district_outcome = 2 if district_name == "DUNFERMLINE AND WEST FIFE"
replace district_outcome = 3 if district_name == "EAST DUNBARTONSHIRE"
replace district_outcome = 2 if district_name == "EAST KILBRIDE, STRATHAVEN AND LESMAHAGOW"
replace district_outcome = 2 if district_name == "EAST LOTHIAN"
replace district_outcome = 2 if district_name == "EAST RENFREWSHIRE"
replace district_outcome = 2 if district_name == "EDINBURGH EAST"
replace district_outcome = 2 if district_name == "EDINBURGH NORTH AND LEITH"
replace district_outcome = 2 if district_name == "EDINBURGH SOUTH"
replace district_outcome = 2 if district_name == "EDINBURGH SOUTH WEST"
replace district_outcome = 3 if district_name == "EDINBURGH WEST"
replace district_outcome = 9 if district_name == "NA H-EILEANAN AN IAR"
replace district_outcome = 2 if district_name == "FALKIRK"
replace district_outcome = 2 if district_name == "GLASGOW CENTRAL"
replace district_outcome = 2 if district_name == "GLASGOW EAST"
replace district_outcome = 2 if district_name == "GLASGOW NORTH"
replace district_outcome = 2 if district_name == "GLASGOW NORTH EAST"
replace district_outcome = 2 if district_name == "GLASGOW NORTH WEST"
replace district_outcome = 2 if district_name == "GLASGOW SOUTH"
replace district_outcome = 2 if district_name == "GLASGOW SOUTH WEST"
replace district_outcome = 2 if district_name == "GLENROTHES"
replace district_outcome = 3 if district_name == "GORDON"
replace district_outcome = 2 if district_name == "INVERCLYDE"
replace district_outcome = 3 if district_name == "INVERNESS, NAIRN, BADENOCH AND STRATHSPEY"
replace district_outcome = 2 if district_name == "KILMARNOCK AND LOUDOUN"
replace district_outcome = 2 if district_name == "KIRKCALDY AND COWDENBEATH"
replace district_outcome = 2 if district_name == "LANARK AND HAMILTON EAST"
replace district_outcome = 2 if district_name == "LINLITHGOW AND EAST FALKIRK"
replace district_outcome = 2 if district_name == "LIVINGSTON"
replace district_outcome = 2 if district_name == "MIDLOTHIAN"
replace district_outcome = 9 if district_name == "MORAY"
replace district_outcome = 2 if district_name == "MOTHERWELL AND WISHAW"
replace district_outcome = 2 if district_name == "NORTH AYRSHIRE AND ARRAN"
replace district_outcome = 3 if district_name == "NORTH EAST FIFE"
replace district_outcome = 2 if district_name == "OCHIL AND SOUTH PERTHSHIRE"
replace district_outcome = 3 if district_name == "ORKNEY AND SHETLAND"
replace district_outcome = 2 if district_name == "PAISLEY AND RENFREWSHIRE NORTH"
replace district_outcome = 2 if district_name == "PAISLEY AND RENFREWSHIRE SOUTH"
replace district_outcome = 9 if district_name == "PERTH AND NORTH PERTHSHIRE"
replace district_outcome = 3 if district_name == "ROSS, SKYE AND LOCHABER"
replace district_outcome = 2 if district_name == "RUTHERGLEN AND HAMILTON WEST"
replace district_outcome = 2 if district_name == "STIRLING"
replace district_outcome = 3 if district_name == "WEST ABERDEENSHIRE AND KINCARDINE"
replace district_outcome = 2 if district_name == "WEST DUNBARTONSHIRE"
replace district_outcome = 2 if district_name == "YNYS MON"
replace district_outcome = 2 if district_name == "DELYN"
replace district_outcome = 2 if district_name == "ALYN AND DEESIDE"
replace district_outcome = 2 if district_name == "WREXHAM"
replace district_outcome = 2 if district_name == "LLANELLI"
replace district_outcome = 2 if district_name == "GOWER"
replace district_outcome = 2 if district_name == "SWANSEA WEST"
replace district_outcome = 2 if district_name == "SWANSEA EAST"
replace district_outcome = 2 if district_name == "ABERAVON"
replace district_outcome = 3 if district_name == "CARDIFF CENTRAL"
replace district_outcome = 1 if district_name == "CARDIFF NORTH"
replace district_outcome = 2 if district_name == "RHONDDA"
replace district_outcome = 2 if district_name == "TORFAEN"
replace district_outcome = 1 if district_name == "MONMOUTH"
replace district_outcome = 2 if district_name == "NEWPORT EAST"
replace district_outcome = 2 if district_name == "NEWPORT WEST"
replace district_outcome = 5 if district_name == "ARFON"
replace district_outcome = 1 if district_name == "ABERCONWY"
replace district_outcome = 1 if district_name == "CLWYD WEST"
replace district_outcome = 2 if district_name == "VALE OF CLWYD"
replace district_outcome = 5 if district_name == "DWYFOR MEIRIONNYDD"
replace district_outcome = 2 if district_name == "CLWYD SOUTH"
replace district_outcome = 1 if district_name == "MONTGOMERYSHIRE"
replace district_outcome = 3 if district_name == "CEREDIGION"
replace district_outcome = 1 if district_name == "PRESELI PEMBROKESHIRE"
replace district_outcome = 1 if district_name == "CARMARTHEN WEST AND SOUTH PEMBROKESHIRE"
replace district_outcome = 5 if district_name == "CARMARTHEN EAST AND DINEFWR"
replace district_outcome = 3 if district_name == "BRECON AND RADNORSHIRE"
replace district_outcome = 2 if district_name == "NEATH"
replace district_outcome = 2 if district_name == "CYNON VALLEY"
replace district_outcome = 2 if district_name == "MERTHYR TYDFIL AND RHYMNEY"
replace district_outcome = 2 if district_name == "BLAENAU GWENT"
replace district_outcome = 2 if district_name == "BRIDGEND"
replace district_outcome = 2 if district_name == "OGMORE"
replace district_outcome = 2 if district_name == "PONTYPRIDD"
replace district_outcome = 2 if district_name == "CAERPHILLY"
replace district_outcome = 2 if district_name == "ISLWYN"
replace district_outcome = 1 if district_name == "VALE OF GLAMORGAN"
replace district_outcome = 2 if district_name == "CARDIFF WEST"
replace district_outcome = 2 if district_name == "CARDIFF SOUTH AND PENARTH"


******************************************
** DISTRICT OUTCOMES (FROM THE DATASET) **
******************************************

* Note: Variable win10 indicates the seat winner in each constituency. Among the sample of constituencies in the dataset, Brighton Pavilion is the only constituency that was coded as won by another party (i.e., "other"). Brighton Pavilion was won by the Green Party.

gen constituency_2010 = win10

recode constituency_2010 1=3 3=4 6=7

label define constituency 2 "Labour" 3 "Conservative" 4 "Liberal Democrat" 5 "SNP" 7 "Green"
label values constituency_2010 constituency


*********************
** COMPETITIVENESS **
*********************

* Margin of victory by district

gen margin = .

replace margin = 12.3083 if district_name == "ALDERSHOT"
replace margin = 39.51442 if district_name == "ALDRIDGE-BROWNHILLS"
replace margin = 23.47499 if district_name == "ALTRINCHAM AND SALE WEST"
replace margin = 1.166282 if district_name == "AMBER VALLEY"
replace margin = 29.81494 if district_name == "ARUNDEL AND SOUTH DOWNS"
replace margin = .3983733 if district_name == "ASHFIELD"
replace margin = 31.34366 if district_name == "ASHFORD"
replace margin = 23.66257 if district_name == "ASHTON-UNDER-LYNE"
replace margin = 23.735 if district_name == "AYLESBURY"
replace margin = 32.40874 if district_name == "BANBURY"
replace margin = 36.5106 if district_name == "BARKING"
replace margin = 29.98027 if district_name == "BARNSLEY CENTRAL"
replace margin = 28.89074 if district_name == "BARNSLEY EAST"
replace margin = 11.8031 if district_name == "BARROW AND FURNESS"
replace margin = 29.68077 if district_name == "BASILDON AND BILLERICAY"
replace margin = 26.01177 if district_name == "BASINGSTOKE"
replace margin = 16.57018 if district_name == "BASSETLAW"
replace margin = 25.2368 if district_name == "BATH"
replace margin = 8.62079 if district_name == "BATLEY AND SPEN"
replace margin = 12.24996 if district_name == "BATTERSEA"
replace margin = 41.49743 if district_name == "BEACONSFIELD"
replace margin = 37.29396 if district_name == "BECKENHAM"
replace margin = 2.999867 if district_name == "BEDFORD"
replace margin = 19.10372 if district_name == "BERMONDSEY AND OLD SOUTHWARK"
replace margin = 6.998101 if district_name == "BERWICK-UPON-TWEED"
replace margin = 21.63894 if district_name == "BETHNAL GREEN AND BOW"
replace margin = 24.41211 if district_name == "BEVERLEY AND HOLDERNESS"
replace margin = 23.59536 if district_name == "BEXHILL AND BATTLE"
replace margin = 23.95443 if district_name == "BEXLEYHEATH AND CRAYFORD"
replace margin = 43.5835 if district_name == "BIRKENHEAD"
replace margin = 3.064636 if district_name == "BIRMINGHAM, EDGBASTON"
replace margin = 9.21904 if district_name == "BIRMINGHAM, ERDINGTON"
replace margin = 7.406571 if district_name == "BIRMINGHAM, HALL GREEN"
replace margin = 24.25598 if district_name == "BIRMINGHAM, HODGE HILL"
replace margin = 28.20026 if district_name == "BIRMINGHAM, LADYWOOD"
replace margin = 6.653274 if district_name == "BIRMINGHAM, NORTHFIELD"
replace margin = 28.32204 if district_name == "BIRMINGHAM, PERRY BARR"
replace margin = 7.478041 if district_name == "BIRMINGHAM, SELLY OAK"
replace margin = 7.348837 if district_name == "BIRMINGHAM, YARDLEY"
replace margin = 12.68475 if district_name == "BISHOP AUCKLAND"
replace margin = 21.66201 if district_name == "BLACKBURN"
replace margin = 35.96948 if district_name == "BLACKLEY AND BROUGHTON"
replace margin = 5.296741 if district_name == "BLACKPOOL NORTH AND CLEVELEYS"
replace margin = 5.26256 if district_name == "BLACKPOOL SOUTH"
replace margin = 20.29925 if district_name == "BLAYDON"
replace margin = 17.28984 if district_name == "BLYTH VALLEY"
replace margin = 27.88141 if district_name == "BOGNOR REGIS AND LITTLEHAMPTON"
replace margin = 25.42057 if district_name == "BOLSOVER"
replace margin = 9.436883 if district_name == "BOLTON NORTH EAST"
replace margin = 21.80083 if district_name == "BOLTON SOUTH EAST"
replace margin = .1933748 if district_name == "BOLTON WEST"
replace margin = 51.31429 if district_name == "BOOTLE"
replace margin = 28.81391 if district_name == "BOSTON AND SKEGNESS"
replace margin = 9.271475 if district_name == "BOSWORTH"
replace margin = 17.55406 if district_name == "BOURNEMOUTH EAST"
replace margin = 13.40167 if district_name == "BOURNEMOUTH WEST"
replace margin = 30.12122 if district_name == "BRACKNELL"
replace margin = .9021925 if district_name == "BRADFORD EAST"
replace margin = 12.16476 if district_name == "BRADFORD SOUTH"
replace margin = 14.20298 if district_name == "BRADFORD WEST"
replace margin = 32.76426 if district_name == "BRAINTREE"
replace margin = 2.967588 if district_name == "BRENT CENTRAL"
replace margin = 15.35049 if district_name == "BRENT NORTH"
replace margin = 3.641774 if district_name == "BRENTFORD AND ISLEWORTH"
replace margin = 33.446 if district_name == "BRENTWOOD AND ONGAR"
replace margin = 16.97282 if district_name == "BRIDGWATER AND WEST SOMERSET"
replace margin = 11.73132 if district_name == "BRIGG AND GOOLE"
replace margin = 3.109706 if district_name == "BRIGHTON, KEMPTOWN"
replace margin = 2.415403 if district_name == "BRIGHTON, PAVILION"
replace margin = 8.267987 if district_name == "BRISTOL EAST"
replace margin = 6.504291 if district_name == "BRISTOL NORTH WEST"
replace margin = 9.785642 if district_name == "BRISTOL SOUTH"
replace margin = 20.53589 if district_name == "BRISTOL WEST"
replace margin = 13.84312 if district_name == "BROADLAND"
replace margin = 31.56437 if district_name == "BROMLEY AND CHISLEHURST"
replace margin = 21.90199 if district_name == "BROMSGROVE"
replace margin = 41.18446 if district_name == "BROXBOURNE"
replace margin = .7377625 if district_name == "BROXTOWE"
replace margin = 65.23844 if district_name == "BUCKINGHAM"
replace margin = 4.344605 if district_name == "BURNLEY"
replace margin = 12.65279 if district_name == "BURTON"
replace margin = 4.988768 if district_name == "BURY NORTH"
replace margin = 6.820395 if district_name == "BURY SOUTH"
replace margin = 21.08382 if district_name == "BURY ST EDMUNDS"
replace margin = 12.41985 if district_name == "CALDER VALLEY"
replace margin = 36.83534 if district_name == "CAMBERWELL AND PECKHAM"
replace margin = .1553197 if district_name == "CAMBORNE AND REDRUTH"
replace margin = 13.54877 if district_name == "CAMBRIDGE"
replace margin = 7.012885 if district_name == "CANNOCK CHASE"
replace margin = 12.29043 if district_name == "CANTERBURY"
replace margin = 2.021327 if district_name == "CARLISLE"
replace margin = 11.4552 if district_name == "CARSHALTON AND WALLINGTON"
replace margin = 12.05304 if district_name == "CASTLE POINT"
replace margin = 17.13289 if district_name == "CENTRAL DEVON"
replace margin = 25.80681 if district_name == "CENTRAL SUFFOLK AND NORTH IPSWICH"
replace margin = 28.06955 if district_name == "CHARNWOOD"
replace margin = 13.85395 if district_name == "CHATHAM AND AYLESFORD"
replace margin = 6.230957 if district_name == "CHEADLE"
replace margin = 9.360174 if district_name == "CHELMSFORD"
replace margin = 41.95604 if district_name == "CHELSEA AND FULHAM"
replace margin = 9.320653 if district_name == "CHELTENHAM"
replace margin = 31.86256 if district_name == "CHESHAM AND AMERSHAM"
replace margin = 1.19767 if district_name == "CHESTERFIELD"
replace margin = 27.95886 if district_name == "CHICHESTER"
replace margin = 30.07238 if district_name == "CHINGFORD AND WOODFORD GREEN"
replace margin = 4.71509 if district_name == "CHIPPENHAM"
replace margin = 23.56742 if district_name == "CHIPPING BARNET"
replace margin = 5.209547 if district_name == "CHORLEY"
replace margin = 31.18423 if district_name == "CHRISTCHURCH"
replace margin = 29.99106 if district_name == "CITIES OF LONDON AND WESTMINSTER"
replace margin = 5.520411 if district_name == "CITY OF CHESTER"
replace margin = 6.631064 if district_name == "CITY OF DURHAM"
replace margin = 27.98507 if district_name == "CLACTON"
replace margin = 9.558333 if district_name == "CLEETHORPES"
replace margin = 15.13253 if district_name == "COLCHESTER"
replace margin = 8.747468 if district_name == "COLNE VALLEY"
replace margin = 13.90902 if district_name == "CONGLETON"
replace margin = 8.958328 if district_name == "COPELAND"
replace margin = 3.493989 if district_name == "CORBY"
replace margin = 27.14197 if district_name == "COVENTRY NORTH EAST"
replace margin = 13.50515 if district_name == "COVENTRY NORTH WEST"
replace margin = 8.372528 if district_name == "COVENTRY SOUTH"
replace margin = 12.47895 if district_name == "CRAWLEY"
replace margin = 11.83541 if district_name == "CREWE AND NANTWICH"
replace margin = 5.796606 if district_name == "CROYDON CENTRAL"
replace margin = 31.89295 if district_name == "CROYDON NORTH"
replace margin = 28.08494 if district_name == "CROYDON SOUTH"
replace margin = 5.945921 if district_name == "DAGENHAM AND RAINHAM"
replace margin = 7.898172 if district_name == "DARLINGTON"
replace margin = 21.22204 if district_name == "DARTFORD"
replace margin = 37.06107 if district_name == "DAVENTRY"
replace margin = 26.12196 if district_name == "DENTON AND REDDISH"
replace margin = 1.359805 if district_name == "DERBY NORTH"
replace margin = 14.86355 if district_name == "DERBY SOUTH"
replace margin = 29.64087 if district_name == "DERBYSHIRE DALES"
replace margin = 28.06431 if district_name == "DEVIZES"
replace margin = 2.825507 if district_name == "DEWSBURY"
replace margin = 8.279594 if district_name == "DON VALLEY"
replace margin = 14.92155 if district_name == "DONCASTER CENTRAL"
replace margin = 26.29752 if district_name == "DONCASTER NORTH"
replace margin = 10.4674 if district_name == "DOVER"
replace margin = 1.68126 if district_name == "DUDLEY NORTH"
replace margin = 10.1035 if district_name == "DUDLEY SOUTH"
replace margin = 19.42382 if district_name == "DULWICH AND WEST NORWOOD"
replace margin = 7.872881 if district_name == "EALING CENTRAL AND ACTON"
replace margin = 19.50795 if district_name == "EALING NORTH"
replace margin = 21.73028 if district_name == "EALING, SOUTHALL"
replace margin = 42.91115 if district_name == "EASINGTON"
replace margin = 17.16643 if district_name == "EAST DEVON"
replace margin = 55.23991 if district_name == "EAST HAM"
replace margin = 26.30123 if district_name == "EAST HAMPSHIRE"
replace margin = 30.88214 if district_name == "EAST SURREY"
replace margin = 22.94564 if district_name == "EAST WORTHING AND SHOREHAM"
replace margin = 26.31209 if district_name == "EAST YORKSHIRE"
replace margin = 6.590055 if district_name == "EASTBOURNE"
replace margin = 7.202237 if district_name == "EASTLEIGH"
replace margin = 29.18703 if district_name == "EDDISBURY"
replace margin = 23.80811 if district_name == "EDMONTON"
replace margin = 9.791332 if district_name == "ELLESMERE PORT AND NESTON"
replace margin = 8.103748 if district_name == "ELMET AND ROTHWELL"
replace margin = 3.962921 if district_name == "ELTHAM"
replace margin = 3.806267 if district_name == "ENFIELD NORTH"
replace margin = 17.19426 if district_name == "ENFIELD, SOUTHGATE"
replace margin = 32.48111 if district_name == "EPPING FOREST"
replace margin = 29.35857 if district_name == "EPSOM AND EWELL"
replace margin = 5.24957 if district_name == "EREWASH"
replace margin = 13.42641 if district_name == "ERITH AND THAMESMEAD"
replace margin = 34.0887 if district_name == "ESHER AND WALTON"
replace margin = 5.207954 if district_name == "EXETER"
replace margin = 31.45092 if district_name == "FAREHAM"
replace margin = 36.58161 if district_name == "FAVERSHAM AND MID KENT"
replace margin = 9.597 if district_name == "FELTHAM AND HESTON"
replace margin = 14.3144 if district_name == "FILTON AND BRADLEY STOKE"
replace margin = 12.31843 if district_name == "FINCHLEY AND GOLDERS GREEN"
replace margin = 19.17045 if district_name == "FOLKESTONE AND HYTHE"
replace margin = 22.68933 if district_name == "FOREST OF DEAN"
replace margin = 30.17853 if district_name == "FYLDE"
replace margin = 21.43916 if district_name == "GAINSBOROUGH"
replace margin = 39.40923 if district_name == "GARSTON AND HALEWOOD"
replace margin = 32.80184 if district_name == "GATESHEAD"
replace margin = 3.857647 if district_name == "GEDLING"
replace margin = 18.55256 if district_name == "GILLINGHAM AND RAINHAM"
replace margin = 4.767158 if district_name == "GLOUCESTER"
replace margin = 30.70581 if district_name == "GOSPORT"
replace margin = 28.08008 if district_name == "GRANTHAM AND STAMFORD"
replace margin = 19.68586 if district_name == "GRAVESHAM"
replace margin = 2.166656 if district_name == "GREAT GRIMSBY"
replace margin = 9.931022 if district_name == "GREAT YARMOUTH"
replace margin = 24.65038 if district_name == "GREENWICH AND WOOLWICH"
replace margin = 14.00471 if district_name == "GUILDFORD"
replace margin = 31.12503 if district_name == "HACKNEY NORTH AND STOKE NEWINGTON"
replace margin = 33.338 if district_name == "HACKNEY SOUTH AND SHOREDITCH"
replace margin = 4.599923 if district_name == "HALESOWEN AND ROWLEY REGIS"
replace margin = 3.379635 if district_name == "HALIFAX"
replace margin = 23.80532 if district_name == "HALTEMPRICE AND HOWDEN"
replace margin = 37.50544 if district_name == "HALTON"
replace margin = 7.479137 if district_name == "HAMMERSMITH"
replace margin = .0795123 if district_name == "HAMPSTEAD AND KILBURN"
replace margin = 17.83056 if district_name == "HARBOROUGH"
replace margin = 11.2243 if district_name == "HARLOW"
replace margin = 1.955433 if district_name == "HARROGATE AND KNARESBOROUGH"
replace margin = 7.088697 if district_name == "HARROW EAST"
replace margin = 6.815422 if district_name == "HARROW WEST"
replace margin = 14.40563 if district_name == "HARTLEPOOL"
replace margin = 23.36123 if district_name == "HARWICH AND NORTH ESSEX"
replace margin = 4.000883 if district_name == "HASTINGS AND RYE"
replace margin = 27.69742 if district_name == "HAVANT"
replace margin = 25.3864 if district_name == "HAYES AND HARLINGTON"
replace margin = 15.17591 if district_name == "HAZEL GROVE"
replace margin = 27.0987 if district_name == "HEMEL HEMPSTEAD"
replace margin = 22.45438 if district_name == "HEMSWORTH"
replace margin = .2285764 if district_name == "HENDON"
replace margin = 30.99402 if district_name == "HENLEY"
replace margin = 5.128046 if district_name == "HEREFORD AND SOUTH HEREFORDSHIRE"
replace margin = 27.87619 if district_name == "HERTFORD AND STORTFORD"
replace margin = 37.2435 if district_name == "HERTSMERE"
replace margin = 13.31095 if district_name == "HEXHAM"
replace margin = 12.94526 if district_name == "HEYWOOD AND MIDDLETON"
replace margin = 9.291376 if district_name == "HIGH PEAK"
replace margin = 27.91416 if district_name == "HITCHIN AND HARPENDEN"
replace margin = 18.19246 if district_name == "HOLBORN AND ST PANCRAS"
replace margin = 30.66305 if district_name == "HORNCHURCH AND UPMINSTER"
replace margin = 12.49046 if district_name == "HORNSEY AND WOOD GREEN"
replace margin = 20.52255 if district_name == "HORSHAM"
replace margin = 28.90508 if district_name == "HOUGHTON AND SUNDERLAND SOUTH"
replace margin = 3.749573 if district_name == "HOVE"
replace margin = 11.03544 if district_name == "HUDDERSFIELD"
replace margin = 19.93698 if district_name == "HUNTINGDON"
replace margin = 7.241282 if district_name == "HYNDBURN"
replace margin = 11.49347 if district_name == "ILFORD NORTH"
replace margin = 22.0488 if district_name == "ILFORD SOUTH"
replace margin = 4.428964 if district_name == "IPSWICH"
replace margin = 14.98207 if district_name == "ISLE OF WIGHT"
replace margin = 27.83364 if district_name == "ISLINGTON NORTH"
replace margin = 8.194237 if district_name == "ISLINGTON SOUTH AND FINSBURY"
replace margin = 33.28176 if district_name == "JARROW"
replace margin = 6.164556 if district_name == "KEIGHLEY"
replace margin = 25.91728 if district_name == "KENILWORTH AND SOUTHAM"
replace margin = 24.51209 if district_name == "KENSINGTON"
replace margin = 19.21484 if district_name == "KETTERING"
replace margin = 13.23738 if district_name == "KINGSTON AND SURBITON"
replace margin = 25.14919 if district_name == "KINGSTON UPON HULL EAST"
replace margin = 1.925445 if district_name == "KINGSTON UPON HULL NORTH"
replace margin = 18.22568 if district_name == "KINGSTON UPON HULL WEST AND HESSLE"
replace margin = 5.103745 if district_name == "KINGSWOOD"
replace margin = 57.51713 if district_name == "KNOWSLEY"
replace margin = .7798412 if district_name == "LANCASTER AND FLEETWOOD"
replace margin = 28.46713 if district_name == "LEEDS CENTRAL"
replace margin = 27.2208 if district_name == "LEEDS EAST"
replace margin = 9.561376 if district_name == "LEEDS NORTH EAST"
replace margin = 20.93462 if district_name == "LEEDS NORTH WEST"
replace margin = 18.10487 if district_name == "LEEDS WEST"
replace margin = 29.34056 if district_name == "LEICESTER EAST"
replace margin = 18.69111 if district_name == "LEICESTER SOUTH"
replace margin = 11.21472 if district_name == "LEICESTER WEST"
replace margin = 27.0933 if district_name == "LEIGH"
replace margin = 15.26713 if district_name == "LEWES"
replace margin = 14.89969 if district_name == "LEWISHAM EAST"
replace margin = 12.94306 if district_name == "LEWISHAM WEST AND PENGE"
replace margin = 30.32266 if district_name == "LEWISHAM, DEPTFORD"
replace margin = 15.97649 if district_name == "LEYTON AND WANSTEAD"
replace margin = 34.29397 if district_name == "LICHFIELD"
replace margin = 2.314035 if district_name == "LINCOLN"
replace margin = 36.52741 if district_name == "LIVERPOOL, RIVERSIDE"
replace margin = 57.71953 if district_name == "LIVERPOOL, WALTON"
replace margin = 18.90331 if district_name == "LIVERPOOL, WAVERTREE"
replace margin = 51.60686 if district_name == "LIVERPOOL, WEST DERBY"
replace margin = 7.085809 if district_name == "LOUGHBOROUGH"
replace margin = 27.47059 if district_name == "LOUTH AND HORNCASTLE"
replace margin = 20.00533 if district_name == "LUDLOW"
replace margin = 17.48105 if district_name == "LUTON NORTH"
replace margin = 5.516866 if district_name == "LUTON SOUTH"
replace margin = 23.88981 if district_name == "MACCLESFIELD"
replace margin = 31.21556 if district_name == "MAIDENHEAD"
replace margin = 12.03605 if district_name == "MAIDSTONE AND THE WEALD"
replace margin = 28.53487 if district_name == "MAKERFIELD"
replace margin = 40.51989 if district_name == "MALDON"
replace margin = 26.14521 if district_name == "MANCHESTER CENTRAL"
replace margin = 17.48989 if district_name == "MANCHESTER, GORTON"
replace margin = 4.205991 if district_name == "MANCHESTER, WITHINGTON"
replace margin = 12.42277 if district_name == "MANSFIELD"
replace margin = 23.66408 if district_name == "MEON VALLEY"
replace margin = 31.1587 if district_name == "MERIDEN"
replace margin = 27.60078 if district_name == "MID BEDFORDSHIRE"
replace margin = 23.85197 if district_name == "MID DERBYSHIRE"
replace margin = .5749338 if district_name == "MID DORSET AND NORTH POOLE"
replace margin = 27.2944 if district_name == "MID NORFOLK"
replace margin = 13.25217 if district_name == "MID SUSSEX"
replace margin = 31.14802 if district_name == "MID WORCESTERSHIRE"
replace margin = 25.9722 if district_name == "MIDDLESBROUGH"
replace margin = 3.628771 if district_name == "MIDDLESBROUGH SOUTH AND EAST CLEVELAND"
replace margin = 16.62893 if district_name == "MILTON KEYNES NORTH"
replace margin = 9.399454 if district_name == "MILTON KEYNES SOUTH"
replace margin = 31.20305 if district_name == "MITCHAM AND MORDEN"
replace margin = 28.81415 if district_name == "MOLE VALLEY"
replace margin = 1.993738 if district_name == "MORECAMBE AND LUNESDALE"
replace margin = 2.253561 if district_name == "MORLEY AND OUTWOOD"
replace margin = 22.59773 if district_name == "NEW FOREST EAST"
replace margin = 35.51669 if district_name == "NEW FOREST WEST"
replace margin = 31.52963 if district_name == "NEWARK"
replace margin = 20.90495 if district_name == "NEWBURY"
replace margin = 21.85789 if district_name == "NEWCASTLE UPON TYNE CENTRAL"
replace margin = 11.76797 if district_name == "NEWCASTLE UPON TYNE EAST"
replace margin = 7.768625 if district_name == "NEWCASTLE UPON TYNE NORTH"
replace margin = 3.593341 if district_name == "NEWCASTLE-UNDER-LYME"
replace margin = 1.083197 if district_name == "NEWTON ABBOT"
replace margin = 23.74403 if district_name == "NORMANTON, PONTEFRACT AND CASTLEFORD"
replace margin = 6.363675 if district_name == "NORTH CORNWALL"
replace margin = 11.34234 if district_name == "NORTH DEVON"
replace margin = 14.0836 if district_name == "NORTH DORSET"
replace margin = 29.47738 if district_name == "NORTH DURHAM"
replace margin = 34.09778 if district_name == "NORTH EAST BEDFORDSHIRE"
replace margin = 31.54771 if district_name == "NORTH EAST CAMBRIDGESHIRE"
replace margin = 5.198367 if district_name == "NORTH EAST DERBYSHIRE"
replace margin = 35.12911 if district_name == "NORTH EAST HAMPSHIRE"
replace margin = 30.13188 if district_name == "NORTH EAST HERTFORDSHIRE"
replace margin = 9.597094 if district_name == "NORTH EAST SOMERSET"
replace margin = 20.78498 if district_name == "NORTH HEREFORDSHIRE"
replace margin = 23.41072 if district_name == "NORTH NORFOLK"
replace margin = 30.51534 if district_name == "NORTH SHROPSHIRE"
replace margin = 13.56898 if district_name == "NORTH SOMERSET"
replace margin = 14.03718 if district_name == "NORTH SWINDON"
replace margin = 31.2115 if district_name == "NORTH THANET"
replace margin = 27.76425 if district_name == "NORTH TYNESIDE"
replace margin = .1142494 if district_name == "NORTH WARWICKSHIRE"
replace margin = 28.61383 if district_name == "NORTH WEST CAMBRIDGESHIRE"
replace margin = 17.37304 if district_name == "NORTH WEST DURHAM"
replace margin = 34.87015 if district_name == "NORTH WEST HAMPSHIRE"
replace margin = 14.45758 if district_name == "NORTH WEST LEICESTERSHIRE"
replace margin = 30.98326 if district_name == "NORTH WEST NORFOLK"
replace margin = 15.36582 if district_name == "NORTH WILTSHIRE"
replace margin = 4.80743 if district_name == "NORTHAMPTON NORTH"
replace margin = 15.40356 if district_name == "NORTHAMPTON SOUTH"
replace margin = 9.163085 if district_name == "NORWICH NORTH"
replace margin = .6519316 if district_name == "NORWICH SOUTH"
replace margin = 21.04675 if district_name == "NOTTINGHAM EAST"
replace margin = 23.73633 if district_name == "NOTTINGHAM NORTH"
replace margin = 4.344308 if district_name == "NOTTINGHAM SOUTH"
replace margin = 4.634234 if district_name == "NUNEATON"
replace margin = 34.85668 if district_name == "OLD BEXLEY AND SIDCUP"
replace margin = .2313567 if district_name == "OLDHAM EAST AND SADDLEWORTH"
replace margin = 21.79445 if district_name == "OLDHAM WEST AND ROYTON"
replace margin = 35.16591 if district_name == "ORPINGTON"
replace margin = 8.869141 if district_name == "OXFORD EAST"
replace margin = .3116147 if district_name == "OXFORD WEST AND ABINGDON"
replace margin = 7.958708 if district_name == "PENDLE"
replace margin = 6.554734 if district_name == "PENISTONE AND STOCKSBRIDGE"
replace margin = 24.9318 if district_name == "PENRITH AND THE BORDER"
replace margin = 10.81977 if district_name == "PETERBOROUGH"
replace margin = 3.82411 if district_name == "PLYMOUTH, MOOR VIEW"
replace margin = 2.61767 if district_name == "PLYMOUTH, SUTTON AND DEVONPORT"
replace margin = 15.89721 if district_name == "POOLE"
replace margin = 12.91221 if district_name == "POPLAR AND LIMEHOUSE"
replace margin = 16.5216 if district_name == "PORTSMOUTH NORTH"
replace margin = 12.60178 if district_name == "PORTSMOUTH SOUTH"
replace margin = 23.79019 if district_name == "PRESTON"
replace margin = 3.379989 if district_name == "PUDSEY"
replace margin = 24.64877 if district_name == "PUTNEY"
replace margin = 42.67619 if district_name == "RAYLEIGH AND WICKFORD"
replace margin = 15.21456 if district_name == "READING EAST"
replace margin = 12.63202 if district_name == "READING WEST"
replace margin = 12.42523 if district_name == "REDCAR"
replace margin = 13.22414 if district_name == "REDDITCH"
replace margin = 27.19397 if district_name == "REIGATE"
replace margin = 28.24603 if district_name == "RIBBLE VALLEY"
replace margin = 43.69056 if district_name == "RICHMOND (YORKS)"
replace margin = 6.902544 if district_name == "RICHMOND PARK"
replace margin = 1.936524 if district_name == "ROCHDALE"
replace margin = 20.74795 if district_name == "ROCHESTER AND STROOD"
replace margin = 26.54272 if district_name == "ROCHFORD AND SOUTHEND EAST"
replace margin = 36.47512 if district_name == "ROMFORD"
replace margin = 8.492205 if district_name == "ROMSEY AND SOUTHAMPTON NORTH"
replace margin = 9.53361 if district_name == "ROSSENDALE AND DARWEN"
replace margin = 12.54545 if district_name == "ROTHER VALLEY"
replace margin = 27.8942 if district_name == "ROTHERHAM"
replace margin = 12.64009 if district_name == "RUGBY"
replace margin = 37.96435 if district_name == "RUISLIP, NORTHWOOD AND PINNER"
replace margin = 34.28661 if district_name == "RUNNYMEDE AND WEYBRIDGE"
replace margin = 29.45033 if district_name == "RUSHCLIFFE"
replace margin = 25.35313 if district_name == "RUTLAND AND MELTON"
replace margin = 28.03436 if district_name == "SAFFRON WALDEN"
replace margin = 13.78422 if district_name == "SALFORD AND ECCLES"
replace margin = 12.30585 if district_name == "SALISBURY"
replace margin = 16.49689 if district_name == "SCARBOROUGH AND WHITBY"
replace margin = 6.882864 if district_name == "SCUNTHORPE"
replace margin = 21.62001 if district_name == "SEDGEFIELD"
replace margin = 7.968966 if district_name == "SEFTON CENTRAL"
replace margin = 23.71056 if district_name == "SELBY AND AINSTY"
replace margin = 35.44973 if district_name == "SEVENOAKS"
replace margin = .3978972 if district_name == "SHEFFIELD CENTRAL"
replace margin = 25.36949 if district_name == "SHEFFIELD SOUTH EAST"
replace margin = 35.03109 if district_name == "SHEFFIELD, BRIGHTSIDE AND HILLSBOROUGH"
replace margin = 29.88951 if district_name == "SHEFFIELD, HALLAM"
replace margin = 14.20812 if district_name == "SHEFFIELD, HEELEY"
replace margin = .4371451 if district_name == "SHERWOOD"
replace margin = 20.11856 if district_name == "SHIPLEY"
replace margin = 14.97596 if district_name == "SHREWSBURY AND ATCHAM"
replace margin = 25.49096 if district_name == "SITTINGBOURNE AND SHEPPEY"
replace margin = 18.18215 if district_name == "SKIPTON AND RIPON"
replace margin = 33.43692 if district_name == "SLEAFORD AND NORTH HYKEHAM"
replace margin = 11.56843 if district_name == "SLOUGH"
replace margin = .3174373 if district_name == "SOLIHULL"
replace margin = 2.997756 if district_name == "SOMERTON AND FROME"
replace margin = 12.90265 if district_name == "SOUTH BASILDON AND EAST THURROCK"
replace margin = 13.27215 if district_name == "SOUTH CAMBRIDGESHIRE"
replace margin = 14.13753 if district_name == "SOUTH DERBYSHIRE"
replace margin = 14.79428 if district_name == "SOUTH DORSET"
replace margin = 10.32256 if district_name == "SOUTH EAST CAMBRIDGESHIRE"
replace margin = 6.489711 if district_name == "SOUTH EAST CORNWALL"
replace margin = 43.59608 if district_name == "SOUTH HOLLAND AND THE DEEPINGS"
replace margin = 28.44422 if district_name == "SOUTH LEICESTERSHIRE"
replace margin = 19.89344 if district_name == "SOUTH NORFOLK"
replace margin = 34.19269 if district_name == "SOUTH NORTHAMPTONSHIRE"
replace margin = 10.79327 if district_name == "SOUTH RIBBLE"
replace margin = 30.42061 if district_name == "SOUTH SHIELDS"
replace margin = 32.89056 if district_name == "SOUTH STAFFORDSHIRE"
replace margin = 16.89941 if district_name == "SOUTH SUFFOLK"
replace margin = 7.521382 if district_name == "SOUTH SWINDON"
replace margin = 16.58285 if district_name == "SOUTH THANET"
replace margin = 32.79041 if district_name == "SOUTH WEST BEDFORDSHIRE"
replace margin = 31.83714 if district_name == "SOUTH WEST DEVON"
replace margin = 26.29075 if district_name == "SOUTH WEST HERTFORDSHIRE"
replace margin = 26.73449 if district_name == "SOUTH WEST NORFOLK"
replace margin = 28.49858 if district_name == "SOUTH WEST SURREY"
replace margin = 21.14937 if district_name == "SOUTH WEST WILTSHIRE"
replace margin = .4323156 if district_name == "SOUTHAMPTON, ITCHEN"
replace margin = 5.460882 if district_name == "SOUTHAMPTON, TEST"
replace margin = 16.67202 if district_name == "SOUTHEND WEST"
replace margin = 13.76694 if district_name == "SOUTHPORT"
replace margin = 21.18003 if district_name == "SPELTHORNE"
replace margin = 4.362638 if district_name == "ST ALBANS"
replace margin = 2.777425 if district_name == "ST AUSTELL AND NEWQUAY"
replace margin = 29.40345 if district_name == "ST HELENS NORTH"
replace margin = 30.64604 if district_name == "ST HELENS SOUTH AND WHISTON"
replace margin = 3.743385 if district_name == "ST IVES"
replace margin = 10.86805 if district_name == "STAFFORD"
replace margin = 15.26646 if district_name == "STAFFORDSHIRE MOORLANDS"
replace margin = 6.712493 if district_name == "STALYBRIDGE AND HYDE"
replace margin = 8.013258 if district_name == "STEVENAGE"
replace margin = 17.33797 if district_name == "STOCKPORT"
replace margin = 16.90212 if district_name == "STOCKTON NORTH"
replace margin = .6602498 if district_name == "STOCKTON SOUTH"
replace margin = 17.14198 if district_name == "STOKE-ON-TRENT CENTRAL"
replace margin = 20.48711 if district_name == "STOKE-ON-TRENT NORTH"
replace margin = 10.36334 if district_name == "STOKE-ON-TRENT SOUTH"
replace margin = 28.14372 if district_name == "STONE"
replace margin = 10.9328 if district_name == "STOURBRIDGE"
replace margin = 22.44866 if district_name == "STRATFORD-ON-AVON"
replace margin = 6.958174 if district_name == "STREATHAM"
replace margin = 19.89535 if district_name == "STRETFORD AND URMSTON"
replace margin = 2.240698 if district_name == "STROUD"
replace margin = 16.62871 if district_name == "SUFFOLK COASTAL"
replace margin = 15.83732 if district_name == "SUNDERLAND CENTRAL"
replace margin = 31.81224 if district_name == "SURREY HEATH"
replace margin = 3.314917 if district_name == "SUTTON AND CHEAM"
replace margin = 33.61403 if district_name == "SUTTON COLDFIELD"
replace margin = 13.12783 if district_name == "TAMWORTH"
replace margin = 32.02892 if district_name == "TATTON"
replace margin = 6.866724 if district_name == "TAUNTON DEANE"
replace margin = 2.367465 if district_name == "TELFORD"
replace margin = 11.69363 if district_name == "TEWKESBURY"
replace margin = 23.46075 if district_name == "THE COTSWOLDS"
replace margin = 20.55778 if district_name == "THE WREKIN"
replace margin = 29.57632 if district_name == "THIRSK AND MALTON"
replace margin = 14.75553 if district_name == "THORNBURY AND YATE"
replace margin = .2007813 if district_name == "THURROCK"
replace margin = 16.97818 if district_name == "TIVERTON AND HONITON"
replace margin = 35.42503 if district_name == "TONBRIDGE AND MALLING"
replace margin = 4.982726 if district_name == "TOOTING"
replace margin = 8.286934 if district_name == "TORBAY"
replace margin = 5.351358 if district_name == "TORRIDGE AND WEST DEVON"
replace margin = 10.29827 if district_name == "TOTNES"
replace margin = 41.6128 if district_name == "TOTTENHAM"
replace margin = .8919783 if district_name == "TRURO AND FALMOUTH"
replace margin = 30.9539 if district_name == "TUNBRIDGE WELLS"
replace margin = 20.32786 if district_name == "TWICKENHAM"
replace margin = 10.89656 if district_name == "TYNEMOUTH"
replace margin = 24.88242 if district_name == "UXBRIDGE AND SOUTH RUISLIP"
replace margin = 24.66023 if district_name == "VAUXHALL"
replace margin = 3.629286 if district_name == "WAKEFIELD"
replace margin = 20.42301 if district_name == "WALLASEY"
replace margin = 2.735789 if district_name == "WALSALL NORTH"
replace margin = 4.292843 if district_name == "WALSALL SOUTH"
replace margin = 23.12046 if district_name == "WALTHAMSTOW"
replace margin = 18.37065 if district_name == "WANSBECK"
replace margin = 24.04466 if district_name == "WANTAGE"
replace margin = 28.10557 if district_name == "WARLEY"
replace margin = 15.31519 if district_name == "WARRINGTON NORTH"
replace margin = 2.83012 if district_name == "WARRINGTON SOUTH"
replace margin = 7.164709 if district_name == "WARWICK AND LEAMINGTON"
replace margin = 30.69052 if district_name == "WASHINGTON AND SUNDERLAND WEST"
replace margin = 2.581148 if district_name == "WATFORD"
replace margin = 1.503686 if district_name == "WAVENEY"
replace margin = 31.25216 if district_name == "WEALDEN"
replace margin = 2.252785 if district_name == "WEAVER VALE"
replace margin = 22.81605 if district_name == "WELLINGBOROUGH"
replace margin = 1.432049 if district_name == "WELLS"
replace margin = 35.57747 if district_name == "WELWYN HATFIELD"
replace margin = 33.05942 if district_name == "WENTWORTH AND DEARNE"
replace margin = 17.64427 if district_name == "WEST BROMWICH EAST"
replace margin = 15.62301 if district_name == "WEST BROMWICH WEST"
replace margin = 6.842004 if district_name == "WEST DORSET"
replace margin = 47.99472 if district_name == "WEST HAM"
replace margin = 8.959627 if district_name == "WEST LANCASHIRE"
replace margin = 27.13718 if district_name == "WEST SUFFOLK"
replace margin = 12.4859 if district_name == "WEST WORCESTERSHIRE"
replace margin = 5.368958 if district_name == "WESTMINSTER NORTH"
replace margin = 23.8196 if district_name == "WESTMORLAND AND LONSDALE"
replace margin = 5.104712 if district_name == "WESTON-SUPER-MARE"
replace margin = 23.7585 if district_name == "WIGAN"
replace margin = 24.07005 if district_name == "WIMBLEDON"
replace margin = 5.447234 if district_name == "WINCHESTER"
replace margin = 38.42462 if district_name == "WINDSOR"
replace margin = 1.330627 if district_name == "WIRRAL SOUTH"
replace margin = 6.187138 if district_name == "WIRRAL WEST"
replace margin = 32.44582 if district_name == "WITHAM"
replace margin = 39.36367 if district_name == "WITNEY"
replace margin = 12.89546 if district_name == "WOKING"
replace margin = 24.74325 if district_name == "WOKINGHAM"
replace margin = 7.118702 if district_name == "WOLVERHAMPTON NORTH EAST"
replace margin = 18.99617 if district_name == "WOLVERHAMPTON SOUTH EAST"
replace margin = 1.720618 if district_name == "WOLVERHAMPTON SOUTH WEST"
replace margin = 6.088945 if district_name == "WORCESTER"
replace margin = 11.65338 if district_name == "WORKINGTON"
replace margin = 10.40023 if district_name == "WORSLEY AND ECCLES SOUTH"
replace margin = 23.8768 if district_name == "WORTHING WEST"
replace margin = 19.85421 if district_name == "WYCOMBE"
replace margin = 30.88017 if district_name == "WYRE AND PRESTON NORTH"
replace margin = 2.9922 if district_name == "WYRE FOREST"
replace margin = 18.5885 if district_name == "WYTHENSHAWE AND SALE EAST"
replace margin = 22.80616 if district_name == "YEOVIL"
replace margin = 13.87819 if district_name == "YORK CENTRAL"
replace margin = 6.919324 if district_name == "YORK OUTER"
replace margin = 4.445024 if district_name == "BELFAST EAST"
replace margin = 6.011948 if district_name == "BELFAST NORTH"
replace margin = 17.33458 if district_name == "BELFAST SOUTH"
replace margin = 54.707 if district_name == "BELFAST WEST"
replace margin = 22.19527 if district_name == "EAST ANTRIM"
replace margin = 15.32189 if district_name == "EAST LONDONDERRY"
replace margin = .3931372 if district_name == "FERMANAGH AND SOUTH TYRONE"
replace margin = 12.73193 if district_name == "FOYLE"
replace margin = 28.69732 if district_name == "LAGAN VALLEY"
replace margin = 37.61569 if district_name == "MID ULSTER"
replace margin = 18.55209 if district_name == "NEWRY AND ARMAGH"
replace margin = 28.19067 if district_name == "NORTH ANTRIM"
replace margin = 47.78233 if district_name == "NORTH DOWN"
replace margin = 3.478491 if district_name == "SOUTH ANTRIM"
replace margin = 19.75158 if district_name == "SOUTH DOWN"
replace margin = 18.07722 if district_name == "STRANGFORD"
replace margin = 8.121693 if district_name == "UPPER BANN"
replace margin = 28.66533 if district_name == "WEST TYRONE"
replace margin = 22.17713 if district_name == "ABERDEEN NORTH"
replace margin = 8.147046 if district_name == "ABERDEEN SOUTH"
replace margin = 34.61184 if district_name == "AIRDRIE AND SHOTTS"
replace margin = 8.645943 if district_name == "ANGUS"
replace margin = 7.589532 if district_name == "ARGYLL AND BUTE"
replace margin = 21.59589 if district_name == "AYR, CARRICK AND CUMNOCK"
replace margin = 10.46899 if district_name == "BANFF AND BUCHAN"
replace margin = 11.57832 if district_name == "BERWICKSHIRE, ROXBURGH AND SELKIRK"
replace margin = 16.77558 if district_name == "CAITHNESS, SUTHERLAND AND EASTER ROSS"
replace margin = 27.34146 if district_name == "CENTRAL AYRSHIRE"
replace margin = 49.75141 if district_name == "COATBRIDGE, CHRYSTON AND BELLSHILL"
replace margin = 33.42649 if district_name == "CUMBERNAULD, KILSYTH AND KIRKINTILLOCH EAST"
replace margin = 14.2775 if district_name == "DUMFRIES AND GALLOWAY"
replace margin = 9.138847 if district_name == "DUMFRIESSHIRE, CLYDESDALE AND TWEEDDALE"
replace margin = 4.48876 if district_name == "DUNDEE EAST"
replace margin = 19.60351 if district_name == "DUNDEE WEST"
replace margin = 11.17535 if district_name == "DUNFERMLINE AND WEST FIFE"
replace margin = 4.554935 if district_name == "EAST DUNBARTONSHIRE"
replace margin = 28.4674 if district_name == "EAST KILBRIDE, STRATHAVEN AND LESMAHAGOW"
replace margin = 24.9344 if district_name == "EAST LOTHIAN"
replace margin = 20.35912 if district_name == "EAST RENFREWSHIRE"
replace margin = 23.03023 if district_name == "EDINBURGH EAST"
replace margin = 3.64051 if district_name == "EDINBURGH NORTH AND LEITH"
replace margin = .7214447 if district_name == "EDINBURGH SOUTH"
replace margin = 18.58035 if district_name == "EDINBURGH SOUTH WEST"
replace margin = 8.187827 if district_name == "EDINBURGH WEST"
replace margin = 12.80832 if district_name == "NA H-EILEANAN AN IAR"
replace margin = 15.44597 if district_name == "FALKIRK"
replace margin = 34.50294 if district_name == "GLASGOW CENTRAL"
replace margin = 36.81134 if district_name == "GLASGOW EAST"
replace margin = 13.16314 if district_name == "GLASGOW NORTH"
replace margin = 54.2079 if district_name == "GLASGOW NORTH EAST"
replace margin = 38.25249 if district_name == "GLASGOW NORTH WEST"
replace margin = 31.57081 if district_name == "GLASGOW SOUTH"
replace margin = 46.1628 if district_name == "GLASGOW SOUTH WEST"
replace margin = 40.61134 if district_name == "GLENROTHES"
replace margin = 13.83496 if district_name == "GORDON"
replace margin = 38.43037 if district_name == "INVERCLYDE"
replace margin = 18.61488 if district_name == "INVERNESS, NAIRN, BADENOCH AND STRATHSPEY"
replace margin = 26.58905 if district_name == "KILMARNOCK AND LOUDOUN"
replace margin = 50.2358 if district_name == "KIRKCALDY AND COWDENBEATH"
replace margin = 28.95132 if district_name == "LANARK AND HAMILTON EAST"
replace margin = 24.39845 if district_name == "LINLITHGOW AND EAST FALKIRK"
replace margin = 22.52489 if district_name == "LIVINGSTON"
replace margin = 26.37225 if district_name == "MIDLOTHIAN"
replace margin = 13.63282 if district_name == "MORAY"
replace margin = 42.95683 if district_name == "MOTHERWELL AND WISHAW"
replace margin = 21.45676 if district_name == "NORTH AYRSHIRE AND ARRAN"
replace margin = 22.58387 if district_name == "NORTH EAST FIFE"
replace margin = 10.2776 if district_name == "OCHIL AND SOUTH PERTHSHIRE"
replace margin = 51.3181 if district_name == "ORKNEY AND SHETLAND"
replace margin = 34.96008 if district_name == "PAISLEY AND RENFREWSHIRE NORTH"
replace margin = 41.53708 if district_name == "PAISLEY AND RENFREWSHIRE SOUTH"
replace margin = 9.072263 if district_name == "PERTH AND NORTH PERTHSHIRE"
replace margin = 37.51651 if district_name == "ROSS, SKYE AND LOCHABER"
replace margin = 44.70318 if district_name == "RUTHERGLEN AND HAMILTON WEST"
replace margin = 17.72806 if district_name == "STIRLING"
replace margin = 8.151344 if district_name == "WEST ABERDEENSHIRE AND KINCARDINE"
replace margin = 41.18677 if district_name == "WEST DUNBARTONSHIRE"
replace margin = 7.144931 if district_name == "YNYS MON"
replace margin = 6.143197 if district_name == "DELYN"
replace margin = 7.311575 if district_name == "ALYN AND DEESIDE"
replace margin = 11.09292 if district_name == "WREXHAM"
replace margin = 12.54905 if district_name == "LLANELLI"
replace margin = 6.43853 if district_name == "GOWER"
replace margin = 1.416009 if district_name == "SWANSEA WEST"
replace margin = 33.16808 if district_name == "SWANSEA EAST"
replace margin = 35.65799 if district_name == "ABERAVON"
replace margin = 12.65802 if district_name == "CARDIFF CENTRAL"
replace margin = .4073063 if district_name == "CARDIFF NORTH"
replace margin = 37.18139 if district_name == "RHONDDA"
replace margin = 24.7237 if district_name == "TORFAEN"
replace margin = 22.4102 if district_name == "MONMOUTH"
replace margin = 4.789828 if district_name == "NEWPORT EAST"
replace margin = 8.922457 if district_name == "NEWPORT WEST"
replace margin = 5.579416 if district_name == "ARFON"
replace margin = 11.33952 if district_name == "ABERCONWY"
replace margin = 16.84291 if district_name == "CLWYD WEST"
replace margin = 7.060843 if district_name == "VALE OF CLWYD"
replace margin = 22.02657 if district_name == "DWYFOR MEIRIONNYDD"
replace margin = 8.171621 if district_name == "CLWYD SOUTH"
replace margin = 3.501612 if district_name == "MONTGOMERYSHIRE"
replace margin = 21.75754 if district_name == "CEREDIGION"
replace margin = 11.6282 if district_name == "PRESELI PEMBROKESHIRE"
replace margin = 8.450391 if district_name == "CARMARTHEN WEST AND SOUTH PEMBROKESHIRE"
replace margin = 9.157875 if district_name == "CARMARTHEN EAST AND DINEFWR"
replace margin = 9.646029 if district_name == "BRECON AND RADNORSHIRE"
replace margin = 26.33209 if district_name == "NEATH"
replace margin = 32.18972 if district_name == "CYNON VALLEY"
replace margin = 12.64497 if district_name == "MERTHYR TYDFIL AND RHYMNEY"
replace margin = 27.54746 if district_name == "BLAENAU GWENT"
replace margin = 5.901374 if district_name == "BRIDGEND"
replace margin = 38.22799 if district_name == "OGMORE"
replace margin = 7.594557 if district_name == "PONTYPRIDD"
replace margin = 27.79644 if district_name == "CAERPHILLY"
replace margin = 35.21797 if district_name == "ISLWYN"
replace margin = 8.849939 if district_name == "VALE OF GLAMORGAN"
replace margin = 11.59969 if district_name == "CARDIFF WEST"
replace margin = 10.61327 if district_name == "CARDIFF SOUTH AND PENARTH"

* Effective number of electoral parties by district

gen enep = .

replace enep = 2.826078 if district_name == "ALDERSHOT"
replace enep = 2.365262 if district_name == "ALDRIDGE-BROWNHILLS"
replace enep = 2.811278 if district_name == "ALTRINCHAM AND SALE WEST"
replace enep = 3.162198 if district_name == "AMBER VALLEY"
replace enep = 2.367891 if district_name == "ARUNDEL AND SOUTH DOWNS"
replace enep = 3.547215 if district_name == "ASHFIELD"
replace enep = 2.664359 if district_name == "ASHFORD"
replace enep = 3.073954 if district_name == "ASHTON-UNDER-LYNE"
replace enep = 2.677043 if district_name == "AYLESBURY"
replace enep = 2.776817 if district_name == "BANBURY"
replace enep = 2.775696 if district_name == "BARKING"
replace enep = 3.294865 if district_name == "BARNSLEY CENTRAL"
replace enep = 3.305143 if district_name == "BARNSLEY EAST"
replace enep = 2.671208 if district_name == "BARROW AND FURNESS"
replace enep = 2.78059 if district_name == "BASILDON AND BILLERICAY"
replace enep = 2.789024 if district_name == "BASINGSTOKE"
replace enep = 2.607562 if district_name == "BASSETLAW"
replace enep = 2.355726 if district_name == "BATH"
replace enep = 3.113553 if district_name == "BATLEY AND SPEN"
replace enep = 2.707709 if district_name == "BATTERSEA"
replace enep = 2.338276 if district_name == "BEACONSFIELD"
replace enep = 2.499741 if district_name == "BECKENHAM"
replace enep = 3.11745 if district_name == "BEDFORD"
replace enep = 2.855289 if district_name == "BERMONDSEY AND OLD SOUTHWARK"
replace enep = 2.895278 if district_name == "BERWICK-UPON-TWEED"
replace enep = 3.448072 if district_name == "BETHNAL GREEN AND BOW"
replace enep = 3.112946 if district_name == "BEVERLEY AND HOLDERNESS"
replace enep = 2.734935 if district_name == "BEXHILL AND BATTLE"
replace enep = 2.890066 if district_name == "BEXLEYHEATH AND CRAYFORD"
replace enep = 2.168861 if district_name == "BIRKENHEAD"
replace enep = 3.015443 if district_name == "BIRMINGHAM, EDGBASTON"
replace enep = 3.195575 if district_name == "BIRMINGHAM, ERDINGTON"
replace enep = 3.892639 if district_name == "BIRMINGHAM, HALL GREEN"
replace enep = 2.734217 if district_name == "BIRMINGHAM, HODGE HILL"
replace enep = 2.494322 if district_name == "BIRMINGHAM, LADYWOOD"
replace enep = 3.280727 if district_name == "BIRMINGHAM, NORTHFIELD"
replace enep = 2.86788 if district_name == "BIRMINGHAM, PERRY BARR"
replace enep = 3.362877 if district_name == "BIRMINGHAM, SELLY OAK"
replace enep = 3.314411 if district_name == "BIRMINGHAM, YARDLEY"
replace enep = 3.561156 if district_name == "BISHOP AUCKLAND"
replace enep = 3.047546 if district_name == "BLACKBURN"
replace enep = 2.77659 if district_name == "BLACKLEY AND BROUGHTON"
replace enep = 3.038669 if district_name == "BLACKPOOL NORTH AND CLEVELEYS"
replace enep = 3.11141 if district_name == "BLACKPOOL SOUTH"
replace enep = 2.773498 if district_name == "BLAYDON"
replace enep = 3.259512 if district_name == "BLYTH VALLEY"
replace enep = 2.893093 if district_name == "BOGNOR REGIS AND LITTLEHAMPTON"
replace enep = 2.944704 if district_name == "BOLSOVER"
replace enep = 2.758435 if district_name == "BOLTON NORTH EAST"
replace enep = 3.1183 if district_name == "BOLTON SOUTH EAST"
replace enep = 3.061559 if district_name == "BOLTON WEST"
replace enep = 2.095599 if district_name == "BOOTLE"
replace enep = 3.114196 if district_name == "BOSTON AND SKEGNESS"
replace enep = 3.101237 if district_name == "BOSWORTH"
replace enep = 2.839441 if district_name == "BOURNEMOUTH EAST"
replace enep = 3.013367 if district_name == "BOURNEMOUTH WEST"
replace enep = 2.813299 if district_name == "BRACKNELL"
replace enep = 3.358999 if district_name == "BRADFORD EAST"
replace enep = 3.379945 if district_name == "BRADFORD SOUTH"
replace enep = 3.097254 if district_name == "BRADFORD WEST"
replace enep = 2.815582 if district_name == "BRAINTREE"
replace enep = 2.644006 if district_name == "BRENT CENTRAL"
replace enep = 2.867088 if district_name == "BRENT NORTH"
replace enep = 3.240598 if district_name == "BRENTFORD AND ISLEWORTH"
replace enep = 2.547459 if district_name == "BRENTWOOD AND ONGAR"
replace enep = 3.145735 if district_name == "BRIDGWATER AND WEST SOMERSET"
replace enep = 2.984602 if district_name == "BRIGG AND GOOLE"
replace enep = 3.308589 if district_name == "BRIGHTON, KEMPTOWN"
replace enep = 3.887491 if district_name == "BRIGHTON, PAVILION"
replace enep = 3.59437 if district_name == "BRISTOL EAST"
replace enep = 3.211691 if district_name == "BRISTOL NORTH WEST"
replace enep = 3.494597 if district_name == "BRISTOL SOUTH"
replace enep = 2.924018 if district_name == "BRISTOL WEST"
replace enep = 2.942474 if district_name == "BROADLAND"
replace enep = 2.743834 if district_name == "BROMLEY AND CHISLEHURST"
replace enep = 3.46564 if district_name == "BROMSGROVE"
replace enep = 2.50012 if district_name == "BROXBOURNE"
replace enep = 3.039789 if district_name == "BROXTOWE"
replace enep = 1.402913 if district_name == "BUCKINGHAM"
replace enep = 3.654369 if district_name == "BURNLEY"
replace enep = 3.046608 if district_name == "BURTON"
replace enep = 3.150335 if district_name == "BURY NORTH"
replace enep = 3.203787 if district_name == "BURY SOUTH"
replace enep = 3.050783 if district_name == "BURY ST EDMUNDS"
replace enep = 3.399564 if district_name == "CALDER VALLEY"
replace enep = 2.38761 if district_name == "CAMBERWELL AND PECKHAM"
replace enep = 3.212879 if district_name == "CAMBORNE AND REDRUTH"
replace enep = 3.519984 if district_name == "CAMBRIDGE"
replace enep = 3.285224 if district_name == "CANNOCK CHASE"
replace enep = 2.988544 if district_name == "CANTERBURY"
replace enep = 3.123 if district_name == "CARLISLE"
replace enep = 2.6438 if district_name == "CARSHALTON AND WALLINGTON"
replace enep = 3.068836 if district_name == "CASTLE POINT"
replace enep = 2.557142 if district_name == "CENTRAL DEVON"
replace enep = 2.864539 if district_name == "CENTRAL SUFFOLK AND NORTH IPSWICH"
replace enep = 2.978899 if district_name == "CHARNWOOD"
replace enep = 2.956053 if district_name == "CHATHAM AND AYLESFORD"
replace enep = 2.513524 if district_name == "CHEADLE"
replace enep = 2.761399 if district_name == "CHELMSFORD"
replace enep = 2.343006 if district_name == "CHELSEA AND FULHAM"
replace enep = 2.337049 if district_name == "CHELTENHAM"
replace enep = 2.219031 if district_name == "CHESHAM AND AMERSHAM"
replace enep = 3.103095 if district_name == "CHESTERFIELD"
replace enep = 2.519923 if district_name == "CHICHESTER"
replace enep = 2.775509 if district_name == "CHINGFORD AND WOODFORD GREEN"
replace enep = 2.602533 if district_name == "CHIPPENHAM"
replace enep = 2.908229 if district_name == "CHIPPING BARNET"
replace enep = 2.836071 if district_name == "CHORLEY"
replace enep = 2.505577 if district_name == "CHRISTCHURCH"
replace enep = 2.745528 if district_name == "CITIES OF LONDON AND WESTMINSTER"
replace enep = 3.074106 if district_name == "CITY OF CHESTER"
replace enep = 2.799631 if district_name == "CITY OF DURHAM"
replace enep = 2.726291 if district_name == "CLACTON"
replace enep = 3.10898 if district_name == "CLEETHORPES"
replace enep = 2.813907 if district_name == "COLCHESTER"
replace enep = 3.462291 if district_name == "COLNE VALLEY"
replace enep = 2.917299 if district_name == "CONGLETON"
replace enep = 2.76484 if district_name == "COPELAND"
replace enep = 2.849951 if district_name == "CORBY"
replace enep = 3.043556 if district_name == "COVENTRY NORTH EAST"
replace enep = 3.268137 if district_name == "COVENTRY NORTH WEST"
replace enep = 3.116422 if district_name == "COVENTRY SOUTH"
replace enep = 3.046269 if district_name == "CRAWLEY"
replace enep = 2.859951 if district_name == "CREWE AND NANTWICH"
replace enep = 3.362981 if district_name == "CROYDON CENTRAL"
replace enep = 2.546526 if district_name == "CROYDON NORTH"
replace enep = 2.824891 if district_name == "CROYDON SOUTH"
replace enep = 3.2836 if district_name == "DAGENHAM AND RAINHAM"
replace enep = 3.219279 if district_name == "DARLINGTON"
replace enep = 2.944493 if district_name == "DARTFORD"
replace enep = 2.599634 if district_name == "DAVENTRY"
replace enep = 2.802029 if district_name == "DENTON AND REDDISH"
replace enep = 3.431474 if district_name == "DERBY NORTH"
replace enep = 3.186123 if district_name == "DERBY SOUTH"
replace enep = 2.767533 if district_name == "DERBYSHIRE DALES"
replace enep = 2.570242 if district_name == "DEVIZES"
replace enep = 3.631299 if district_name == "DEWSBURY"
replace enep = 3.636969 if district_name == "DON VALLEY"
replace enep = 3.614223 if district_name == "DONCASTER CENTRAL"
replace enep = 3.249142 if district_name == "DONCASTER NORTH"
replace enep = 2.999674 if district_name == "DOVER"
replace enep = 3.253938 if district_name == "DUDLEY NORTH"
replace enep = 3.067175 if district_name == "DUDLEY SOUTH"
replace enep = 2.934154 if district_name == "DULWICH AND WEST NORWOOD"
replace enep = 3.201589 if district_name == "EALING CENTRAL AND ACTON"
replace enep = 2.718564 if district_name == "EALING NORTH"
replace enep = 2.652247 if district_name == "EALING, SOUTHALL"
replace enep = 2.509266 if district_name == "EASINGTON"
replace enep = 2.862685 if district_name == "EAST DEVON"
replace enep = 1.876988 if district_name == "EAST HAM"
replace enep = 2.365767 if district_name == "EAST HAMPSHIRE"
replace enep = 2.487335 if district_name == "EAST SURREY"
replace enep = 3.008319 if district_name == "EAST WORTHING AND SHOREHAM"
replace enep = 3.163224 if district_name == "EAST YORKSHIRE"
replace enep = 2.533654 if district_name == "EASTBOURNE"
replace enep = 2.618725 if district_name == "EASTLEIGH"
replace enep = 2.731794 if district_name == "EDDISBURY"
replace enep = 2.568316 if district_name == "EDMONTON"
replace enep = 2.896733 if district_name == "ELLESMERE PORT AND NESTON"
replace enep = 3.033695 if district_name == "ELMET AND ROTHWELL"
replace enep = 3.010118 if district_name == "ELTHAM"
replace enep = 2.90754 if district_name == "ENFIELD NORTH"
replace enep = 2.715925 if district_name == "ENFIELD, SOUTHGATE"
replace enep = 2.761364 if district_name == "EPPING FOREST"
replace enep = 2.477 if district_name == "EPSOM AND EWELL"
replace enep = 3.252197 if district_name == "EREWASH"
replace enep = 3.101087 if district_name == "ERITH AND THAMESMEAD"
replace enep = 2.371062 if district_name == "ESHER AND WALTON"
replace enep = 3.354621 if district_name == "EXETER"
replace enep = 2.601225 if district_name == "FAREHAM"
replace enep = 2.604835 if district_name == "FAVERSHAM AND MID KENT"
replace enep = 3.043649 if district_name == "FELTHAM AND HESTON"
replace enep = 3.310241 if district_name == "FILTON AND BRADLEY STOKE"
replace enep = 2.820986 if district_name == "FINCHLEY AND GOLDERS GREEN"
replace enep = 2.844822 if district_name == "FOLKESTONE AND HYTHE"
replace enep = 3.039034 if district_name == "FOREST OF DEAN"
replace enep = 2.756177 if district_name == "FYLDE"
replace enep = 2.878862 if district_name == "GAINSBOROUGH"
replace enep = 2.368589 if district_name == "GARSTON AND HALEWOOD"
replace enep = 2.738644 if district_name == "GATESHEAD"
replace enep = 2.999542 if district_name == "GEDLING"
replace enep = 3.069961 if district_name == "GILLINGHAM AND RAINHAM"
replace enep = 3.110387 if district_name == "GLOUCESTER"
replace enep = 2.893639 if district_name == "GOSPORT"
replace enep = 2.94362 if district_name == "GRANTHAM AND STAMFORD"
replace enep = 2.942297 if district_name == "GRAVESHAM"
replace enep = 3.832426 if district_name == "GREAT GRIMSBY"
replace enep = 3.119607 if district_name == "GREAT YARMOUTH"
replace enep = 2.949316 if district_name == "GREENWICH AND WOOLWICH"
replace enep = 2.265256 if district_name == "GUILDFORD"
replace enep = 2.609947 if district_name == "HACKNEY NORTH AND STOKE NEWINGTON"
replace enep = 2.619809 if district_name == "HACKNEY SOUTH AND SHOREDITCH"
replace enep = 3.032949 if district_name == "HALESOWEN AND ROWLEY REGIS"
replace enep = 3.350384 if district_name == "HALIFAX"
replace enep = 2.84931 if district_name == "HALTEMPRICE AND HOWDEN"
replace enep = 2.531253 if district_name == "HALTON"
replace enep = 2.852528 if district_name == "HAMMERSMITH"
replace enep = 3.198512 if district_name == "HAMPSTEAD AND KILBURN"
replace enep = 2.814162 if district_name == "HARBOROUGH"
replace enep = 2.973095 if district_name == "HARLOW"
replace enep = 2.463544 if district_name == "HARROGATE AND KNARESBOROUGH"
replace enep = 2.766709 if district_name == "HARROW EAST"
replace enep = 2.838276 if district_name == "HARROW WEST"
replace enep = 3.367908 if district_name == "HARTLEPOOL"
replace enep = 3.131157 if district_name == "HARWICH AND NORTH ESSEX"
replace enep = 3.003554 if district_name == "HASTINGS AND RYE"
replace enep = 2.848227 if district_name == "HAVANT"
replace enep = 2.507471 if district_name == "HAYES AND HARLINGTON"
replace enep = 2.707855 if district_name == "HAZEL GROVE"
replace enep = 2.878344 if district_name == "HEMEL HEMPSTEAD"
replace enep = 3.123291 if district_name == "HEMSWORTH"
replace enep = 2.684896 if district_name == "HENDON"
replace enep = 2.546739 if district_name == "HENLEY"
replace enep = 2.567711 if district_name == "HEREFORD AND SOUTH HEREFORDSHIRE"
replace enep = 2.64436 if district_name == "HERTFORD AND STORTFORD"
replace enep = 2.621598 if district_name == "HERTSMERE"
replace enep = 3.139266 if district_name == "HEXHAM"
replace enep = 3.42063 if district_name == "HEYWOOD AND MIDDLETON"
replace enep = 3.161103 if district_name == "HIGH PEAK"
replace enep = 2.571722 if district_name == "HITCHIN AND HARPENDEN"
replace enep = 3.000997 if district_name == "HOLBORN AND ST PANCRAS"
replace enep = 2.977581 if district_name == "HORNCHURCH AND UPMINSTER"
replace enep = 2.775955 if district_name == "HORNSEY AND WOOD GREEN"
replace enep = 2.561701 if district_name == "HORSHAM"
replace enep = 3.00408 if district_name == "HOUGHTON AND SUNDERLAND SOUTH"
replace enep = 3.359057 if district_name == "HOVE"
replace enep = 3.416961 if district_name == "HUDDERSFIELD"
replace enep = 2.941892 if district_name == "HUNTINGDON"
replace enep = 3.266316 if district_name == "HYNDBURN"
replace enep = 2.8994 if district_name == "ILFORD NORTH"
replace enep = 2.862592 if district_name == "ILFORD SOUTH"
replace enep = 3.235171 if district_name == "IPSWICH"
replace enep = 2.974513 if district_name == "ISLE OF WIGHT"
replace enep = 2.568484 if district_name == "ISLINGTON NORTH"
replace enep = 3.003698 if district_name == "ISLINGTON SOUTH AND FINSBURY"
replace enep = 2.686514 if district_name == "JARROW"
replace enep = 3.04222 if district_name == "KEIGHLEY"
replace enep = 2.598294 if district_name == "KENILWORTH AND SOUTHAM"
replace enep = 2.816936 if district_name == "KENSINGTON"
replace enep = 2.789967 if district_name == "KETTERING"
replace enep = 2.558686 if district_name == "KINGSTON AND SURBITON"
replace enep = 3.146227 if district_name == "KINGSTON UPON HULL EAST"
replace enep = 3.186523 if district_name == "KINGSTON UPON HULL NORTH"
replace enep = 3.463792 if district_name == "KINGSTON UPON HULL WEST AND HESSLE"
replace enep = 3.13774 if district_name == "KINGSWOOD"
replace enep = 1.884604 if district_name == "KNOWSLEY"
replace enep = 3.395182 if district_name == "LANCASTER AND FLEETWOOD"
replace enep = 2.971814 if district_name == "LEEDS CENTRAL"
replace enep = 2.887851 if district_name == "LEEDS EAST"
replace enep = 3.018438 if district_name == "LEEDS NORTH EAST"
replace enep = 2.931237 if district_name == "LEEDS NORTH WEST"
replace enep = 3.532262 if district_name == "LEEDS WEST"
replace enep = 2.692287 if district_name == "LEICESTER EAST"
replace enep = 3.05731 if district_name == "LEICESTER SOUTH"
replace enep = 3.585277 if district_name == "LEICESTER WEST"
replace enep = 3.148588 if district_name == "LEIGH"
replace enep = 2.442002 if district_name == "LEWES"
replace enep = 3.11121 if district_name == "LEWISHAM EAST"
replace enep = 3.182402 if district_name == "LEWISHAM WEST AND PENGE"
replace enep = 2.729902 if district_name == "LEWISHAM, DEPTFORD"
replace enep = 3.150559 if district_name == "LEYTON AND WANSTEAD"
replace enep = 2.639467 if district_name == "LICHFIELD"
replace enep = 3.238785 if district_name == "LINCOLN"
replace enep = 2.398924 if district_name == "LIVERPOOL, RIVERSIDE"
replace enep = 1.833903 if district_name == "LIVERPOOL, WALTON"
replace enep = 2.466508 if district_name == "LIVERPOOL, WAVERTREE"
replace enep = 2.228291 if district_name == "LIVERPOOL, WEST DERBY"
replace enep = 3.055979 if district_name == "LOUGHBOROUGH"
replace enep = 3.014119 if district_name == "LOUTH AND HORNCASTLE"
replace enep = 2.544121 if district_name == "LUDLOW"
replace enep = 2.789789 if district_name == "LUTON NORTH"
replace enep = 3.708034 if district_name == "LUTON SOUTH"
replace enep = 3.13871 if district_name == "MACCLESFIELD"
replace enep = 2.276942 if district_name == "MAIDENHEAD"
replace enep = 2.695559 if district_name == "MAIDSTONE AND THE WEALD"
replace enep = 3.158624 if district_name == "MAKERFIELD"
replace enep = 2.409438 if district_name == "MALDON"
replace enep = 2.731196 if district_name == "MANCHESTER CENTRAL"
replace enep = 2.688974 if district_name == "MANCHESTER, GORTON"
replace enep = 2.659571 if district_name == "MANCHESTER, WITHINGTON"
replace enep = 3.775909 if district_name == "MANSFIELD"
replace enep = 2.337862 if district_name == "MEON VALLEY"
replace enep = 2.895586 if district_name == "MERIDEN"
replace enep = 2.760255 if district_name == "MID BEDFORDSHIRE"
replace enep = 2.960269 if district_name == "MID DERBYSHIRE"
replace enep = 2.456536 if district_name == "MID DORSET AND NORTH POOLE"
replace enep = 3.038622 if district_name == "MID NORFOLK"
replace enep = 2.481472 if district_name == "MID SUSSEX"
replace enep = 2.64547 if district_name == "MID WORCESTERSHIRE"
replace enep = 3.326813 if district_name == "MIDDLESBROUGH"
replace enep = 3.220849 if district_name == "MIDDLESBROUGH SOUTH AND EAST CLEVELAND"
replace enep = 3.207945 if district_name == "MILTON KEYNES NORTH"
replace enep = 3.214023 if district_name == "MILTON KEYNES SOUTH"
replace enep = 2.511209 if district_name == "MITCHAM AND MORDEN"
replace enep = 2.37247 if district_name == "MOLE VALLEY"
replace enep = 2.870245 if district_name == "MORECAMBE AND LUNESDALE"
replace enep = 3.328587 if district_name == "MORLEY AND OUTWOOD"
replace enep = 2.608253 if district_name == "NEW FOREST EAST"
replace enep = 2.416872 if district_name == "NEW FOREST WEST"
replace enep = 2.622119 if district_name == "NEWARK"
replace enep = 2.236946 if district_name == "NEWBURY"
replace enep = 3.206126 if district_name == "NEWCASTLE UPON TYNE CENTRAL"
replace enep = 2.931242 if district_name == "NEWCASTLE UPON TYNE EAST"
replace enep = 3.206567 if district_name == "NEWCASTLE UPON TYNE NORTH"
replace enep = 3.256482 if district_name == "NEWCASTLE-UNDER-LYME"
replace enep = 2.700805 if district_name == "NEWTON ABBOT"
replace enep = 3.019885 if district_name == "NORMANTON, PONTEFRACT AND CASTLEFORD"
replace enep = 2.444409 if district_name == "NORTH CORNWALL"
replace enep = 2.755256 if district_name == "NORTH DEVON"
replace enep = 2.481394 if district_name == "NORTH DORSET"
replace enep = 2.885415 if district_name == "NORTH DURHAM"
replace enep = 2.587777 if district_name == "NORTH EAST BEDFORDSHIRE"
replace enep = 2.90973 if district_name == "NORTH EAST CAMBRIDGESHIRE"
replace enep = 3.20953 if district_name == "NORTH EAST DERBYSHIRE"
replace enep = 2.256255 if district_name == "NORTH EAST HAMPSHIRE"
replace enep = 2.699362 if district_name == "NORTH EAST HERTFORDSHIRE"
replace enep = 3.107534 if district_name == "NORTH EAST SOMERSET"
replace enep = 2.676382 if district_name == "NORTH HEREFORDSHIRE"
replace enep = 2.397269 if district_name == "NORTH NORFOLK"
replace enep = 2.898167 if district_name == "NORTH SHROPSHIRE"
replace enep = 2.603119 if district_name == "NORTH SOMERSET"
replace enep = 3.089301 if district_name == "NORTH SWINDON"
replace enep = 2.738563 if district_name == "NORTH THANET"
replace enep = 2.888443 if district_name == "NORTH TYNESIDE"
replace enep = 2.948843 if district_name == "NORTH WARWICKSHIRE"
replace enep = 2.950838 if district_name == "NORTH WEST CAMBRIDGESHIRE"
replace enep = 3.426795 if district_name == "NORTH WEST DURHAM"
replace enep = 2.411445 if district_name == "NORTH WEST HAMPSHIRE"
replace enep = 3.110465 if district_name == "NORTH WEST LEICESTERSHIRE"
replace enep = 2.711432 if district_name == "NORTH WEST NORFOLK"
replace enep = 2.480489 if district_name == "NORTH WILTSHIRE"
replace enep = 3.530005 if district_name == "NORTHAMPTON NORTH"
replace enep = 3.58542 if district_name == "NORTHAMPTON SOUTH"
replace enep = 3.330112 if district_name == "NORWICH NORTH"
replace enep = 4.093625 if district_name == "NORWICH SOUTH"
replace enep = 3.095064 if district_name == "NOTTINGHAM EAST"
replace enep = 3.019767 if district_name == "NOTTINGHAM NORTH"
replace enep = 3.307829 if district_name == "NOTTINGHAM SOUTH"
replace enep = 2.977528 if district_name == "NUNEATON"
replace enep = 2.778116 if district_name == "OLD BEXLEY AND SIDCUP"
replace enep = 3.611953 if district_name == "OLDHAM EAST AND SADDLEWORTH"
replace enep = 3.253286 if district_name == "OLDHAM WEST AND ROYTON"
replace enep = 2.344955 if district_name == "ORPINGTON"
replace enep = 3.031038 if district_name == "OXFORD EAST"
replace enep = 2.716447 if district_name == "OXFORD WEST AND ABINGDON"
replace enep = 3.41166 if district_name == "PENDLE"
replace enep = 3.454706 if district_name == "PENISTONE AND STOCKSBRIDGE"
replace enep = 2.603408 if district_name == "PENRITH AND THE BORDER"
replace enep = 3.401635 if district_name == "PETERBOROUGH"
replace enep = 3.504064 if district_name == "PLYMOUTH, MOOR VIEW"
replace enep = 3.528098 if district_name == "PLYMOUTH, SUTTON AND DEVONPORT"
replace enep = 2.895742 if district_name == "POOLE"
replace enep = 3.516085 if district_name == "POPLAR AND LIMEHOUSE"
replace enep = 3.164242 if district_name == "PORTSMOUTH NORTH"
replace enep = 2.929196 if district_name == "PORTSMOUTH SOUTH"
replace enep = 2.930243 if district_name == "PRESTON"
replace enep = 3.165738 if district_name == "PUDSEY"
replace enep = 2.667268 if district_name == "PUTNEY"
replace enep = 2.585508 if district_name == "RAYLEIGH AND WICKFORD"
replace enep = 3.109703 if district_name == "READING EAST"
replace enep = 3.10974 if district_name == "READING WEST"
replace enep = 2.996178 if district_name == "REDCAR"
replace enep = 3.17761 if district_name == "REDDITCH"
replace enep = 2.705277 if district_name == "REIGATE"
replace enep = 2.871913 if district_name == "RIBBLE VALLEY"
replace enep = 2.19811 if district_name == "RICHMOND (YORKS)"
replace enep = 2.309034 if district_name == "RICHMOND PARK"
replace enep = 3.447186 if district_name == "ROCHDALE"
replace enep = 2.842277 if district_name == "ROCHESTER AND STROOD"
replace enep = 3.270836 if district_name == "ROCHFORD AND SOUTHEND EAST"
replace enep = 2.679268 if district_name == "ROMFORD"
replace enep = 2.367455 if district_name == "ROMSEY AND SOUTHAMPTON NORTH"
replace enep = 3.179246 if district_name == "ROSSENDALE AND DARWEN"
replace enep = 3.477997 if district_name == "ROTHER VALLEY"
replace enep = 3.517794 if district_name == "ROTHERHAM"
replace enep = 3.003677 if district_name == "RUGBY"
replace enep = 2.513958 if district_name == "RUISLIP, NORTHWOOD AND PINNER"
replace enep = 2.619901 if district_name == "RUNNYMEDE AND WEYBRIDGE"
replace enep = 2.8239 if district_name == "RUSHCLIFFE"
replace enep = 2.840645 if district_name == "RUTLAND AND MELTON"
replace enep = 2.53452 if district_name == "SAFFRON WALDEN"
replace enep = 3.525434 if district_name == "SALFORD AND ECCLES"
replace enep = 2.592772 if district_name == "SALISBURY"
replace enep = 3.267367 if district_name == "SCARBOROUGH AND WHITBY"
replace enep = 3.332952 if district_name == "SCUNTHORPE"
replace enep = 3.269756 if district_name == "SEDGEFIELD"
replace enep = 3.01005 if district_name == "SEFTON CENTRAL"
replace enep = 2.904073 if district_name == "SELBY AND AINSTY"
replace enep = 2.564909 if district_name == "SEVENOAKS"
replace enep = 2.850694 if district_name == "SHEFFIELD CENTRAL"
replace enep = 3.052077 if district_name == "SHEFFIELD SOUTH EAST"
replace enep = 2.731572 if district_name == "SHEFFIELD, BRIGHTSIDE AND HILLSBOROUGH"
replace enep = 2.713626 if district_name == "SHEFFIELD, HALLAM"
replace enep = 3.366144 if district_name == "SHEFFIELD, HEELEY"
replace enep = 3.036983 if district_name == "SHERWOOD"
replace enep = 2.796132 if district_name == "SHIPLEY"
replace enep = 3.114705 if district_name == "SHREWSBURY AND ATCHAM"
replace enep = 2.92591 if district_name == "SITTINGBOURNE AND SHEPPEY"
replace enep = 2.677535 if district_name == "SKIPTON AND RIPON"
replace enep = 2.953815 if district_name == "SLEAFORD AND NORTH HYKEHAM"
replace enep = 2.857563 if district_name == "SLOUGH"
replace enep = 2.67037 if district_name == "SOLIHULL"
replace enep = 2.343464 if district_name == "SOMERTON AND FROME"
replace enep = 3.193503 if district_name == "SOUTH BASILDON AND EAST THURROCK"
replace enep = 2.824494 if district_name == "SOUTH CAMBRIDGESHIRE"
replace enep = 2.999256 if district_name == "SOUTH DERBYSHIRE"
replace enep = 3.008036 if district_name == "SOUTH DORSET"
replace enep = 2.635693 if district_name == "SOUTH EAST CAMBRIDGESHIRE"
replace enep = 2.760852 if district_name == "SOUTH EAST CORNWALL"
replace enep = 2.513067 if district_name == "SOUTH HOLLAND AND THE DEEPINGS"
replace enep = 2.973201 if district_name == "SOUTH LEICESTERSHIRE"
replace enep = 2.856798 if district_name == "SOUTH NORFOLK"
replace enep = 2.622455 if district_name == "SOUTH NORTHAMPTONSHIRE"
replace enep = 2.867958 if district_name == "SOUTH RIBBLE"
replace enep = 2.873492 if district_name == "SOUTH SHIELDS"
replace enep = 2.800872 if district_name == "SOUTH STAFFORDSHIRE"
replace enep = 2.867907 if district_name == "SOUTH SUFFOLK"
replace enep = 3.076091 if district_name == "SOUTH SWINDON"
replace enep = 2.818783 if district_name == "SOUTH THANET"
replace enep = 2.775495 if district_name == "SOUTH WEST BEDFORDSHIRE"
replace enep = 2.557768 if district_name == "SOUTH WEST DEVON"
replace enep = 2.581406 if district_name == "SOUTH WEST HERTFORDSHIRE"
replace enep = 3.124307 if district_name == "SOUTH WEST NORFOLK"
replace enep = 2.2719 if district_name == "SOUTH WEST SURREY"
replace enep = 2.658855 if district_name == "SOUTH WEST WILTSHIRE"
replace enep = 3.198754 if district_name == "SOUTHAMPTON, ITCHEN"
replace enep = 3.238321 if district_name == "SOUTHAMPTON, TEST"
replace enep = 3.109527 if district_name == "SOUTHEND WEST"
replace enep = 2.590343 if district_name == "SOUTHPORT"
replace enep = 3.09427 if district_name == "SPELTHORNE"
replace enep = 3.020032 if district_name == "ST ALBANS"
replace enep = 2.832971 if district_name == "ST AUSTELL AND NEWQUAY"
replace enep = 2.775815 if district_name == "ST HELENS NORTH"
replace enep = 2.752179 if district_name == "ST HELENS SOUTH AND WHISTON"
replace enep = 2.895573 if district_name == "ST IVES"
replace enep = 3.029464 if district_name == "STAFFORD"
replace enep = 3.046551 if district_name == "STAFFORDSHIRE MOORLANDS"
replace enep = 3.350709 if district_name == "STALYBRIDGE AND HYDE"
replace enep = 3.18055 if district_name == "STEVENAGE"
replace enep = 3.221054 if district_name == "STOCKPORT"
replace enep = 3.438932 if district_name == "STOCKTON NORTH"
replace enep = 3.086262 if district_name == "STOCKTON SOUTH"
replace enep = 3.790182 if district_name == "STOKE-ON-TRENT CENTRAL"
replace enep = 3.392694 if district_name == "STOKE-ON-TRENT NORTH"
replace enep = 3.628703 if district_name == "STOKE-ON-TRENT SOUTH"
replace enep = 2.84187 if district_name == "STONE"
replace enep = 3.193339 if district_name == "STOURBRIDGE"
replace enep = 2.75104 if district_name == "STRATFORD-ON-AVON"
replace enep = 2.895422 if district_name == "STREATHAM"
replace enep = 2.868491 if district_name == "STRETFORD AND URMSTON"
replace enep = 2.933117 if district_name == "STROUD"
replace enep = 2.998166 if district_name == "SUFFOLK COASTAL"
replace enep = 3.006707 if district_name == "SUNDERLAND CENTRAL"
replace enep = 2.419079 if district_name == "SURREY HEATH"
replace enep = 2.53836 if district_name == "SUTTON AND CHEAM"
replace enep = 2.721196 if district_name == "SUTTON COLDFIELD"
replace enep = 2.899781 if district_name == "TAMWORTH"
replace enep = 2.620083 if district_name == "TATTON"
replace enep = 2.365618 if district_name == "TAUNTON DEANE"
replace enep = 3.224829 if district_name == "TELFORD"
replace enep = 2.745792 if district_name == "TEWKESBURY"
replace enep = 2.616398 if district_name == "THE COTSWOLDS"
replace enep = 2.989202 if district_name == "THE WREKIN"
replace enep = 2.794179 if district_name == "THIRSK AND MALTON"
replace enep = 2.417624 if district_name == "THORNBURY AND YATE"
replace enep = 3.40491 if district_name == "THURROCK"
replace enep = 2.66041 if district_name == "TIVERTON AND HONITON"
replace enep = 2.475397 if district_name == "TONBRIDGE AND MALLING"
replace enep = 2.777745 if district_name == "TOOTING"
replace enep = 2.644544 if district_name == "TORBAY"
replace enep = 2.650548 if district_name == "TORRIDGE AND WEST DEVON"
replace enep = 2.880233 if district_name == "TOTNES"
replace enep = 2.451269 if district_name == "TOTTENHAM"
replace enep = 2.837483 if district_name == "TRURO AND FALMOUTH"
replace enep = 2.536016 if district_name == "TUNBRIDGE WELLS"
replace enep = 2.390822 if district_name == "TWICKENHAM"
replace enep = 2.882637 if district_name == "TYNEMOUTH"
replace enep = 3.025879 if district_name == "UXBRIDGE AND SOUTH RUISLIP"
replace enep = 2.794567 if district_name == "VAUXHALL"
replace enep = 3.195652 if district_name == "WAKEFIELD"
replace enep = 2.588342 if district_name == "WALLASEY"
replace enep = 3.503705 if district_name == "WALSALL NORTH"
replace enep = 3.220134 if district_name == "WALSALL SOUTH"
replace enep = 2.689528 if district_name == "WALTHAMSTOW"
replace enep = 3.12589 if district_name == "WANSBECK"
replace enep = 2.704167 if district_name == "WANTAGE"
replace enep = 2.704169 if district_name == "WARLEY"
replace enep = 2.913508 if district_name == "WARRINGTON NORTH"
replace enep = 3.191159 if district_name == "WARRINGTON SOUTH"
replace enep = 2.934579 if district_name == "WARWICK AND LEAMINGTON"
replace enep = 2.802905 if district_name == "WASHINGTON AND SUNDERLAND WEST"
replace enep = 3.33982 if district_name == "WATFORD"
replace enep = 3.005339 if district_name == "WAVENEY"
replace enep = 2.516392 if district_name == "WEALDEN"
replace enep = 3.157657 if district_name == "WEAVER VALE"
replace enep = 3.027511 if district_name == "WELLINGBOROUGH"
replace enep = 2.623197 if district_name == "WELLS"
replace enep = 2.510645 if district_name == "WELWYN HATFIELD"
replace enep = 3.072705 if district_name == "WENTWORTH AND DEARNE"
replace enep = 3.070352 if district_name == "WEST BROMWICH EAST"
replace enep = 3.192071 if district_name == "WEST BROMWICH WEST"
replace enep = 2.509012 if district_name == "WEST DORSET"
replace enep = 2.301268 if district_name == "WEST HAM"
replace enep = 2.820163 if district_name == "WEST LANCASHIRE"
replace enep = 2.952857 if district_name == "WEST SUFFOLK"
replace enep = 2.485135 if district_name == "WEST WORCESTERSHIRE"
replace enep = 2.771717 if district_name == "WESTMINSTER NORTH"
replace enep = 2.03338 if district_name == "WESTMORLAND AND LONSDALE"
replace enep = 2.751083 if district_name == "WESTON-SUPER-MARE"
replace enep = 3.062841 if district_name == "WIGAN"
replace enep = 2.829688 if district_name == "WIMBLEDON"
replace enep = 2.355169 if district_name == "WINCHESTER"
replace enep = 2.314589 if district_name == "WINDSOR"
replace enep = 2.853199 if district_name == "WIRRAL SOUTH"
replace enep = 2.928067 if district_name == "WIRRAL WEST"
replace enep = 2.850176 if district_name == "WITHAM"
replace enep = 2.47774 if district_name == "WITNEY"
replace enep = 2.494819 if district_name == "WOKING"
replace enep = 2.700835 if district_name == "WOKINGHAM"
replace enep = 3.184883 if district_name == "WOLVERHAMPTON NORTH EAST"
replace enep = 2.968549 if district_name == "WOLVERHAMPTON SOUTH EAST"
replace enep = 2.902021 if district_name == "WOLVERHAMPTON SOUTH WEST"
replace enep = 3.247096 if district_name == "WORCESTER"
replace enep = 2.916425 if district_name == "WORKINGTON"
replace enep = 3.121103 if district_name == "WORSLEY AND ECCLES SOUTH"
replace enep = 2.752826 if district_name == "WORTHING WEST"
replace enep = 2.845429 if district_name == "WYCOMBE"
replace enep = 2.714796 if district_name == "WYRE AND PRESTON NORTH"
replace enep = 3.484869 if district_name == "WYRE FOREST"
replace enep = 3.192079 if district_name == "WYTHENSHAWE AND SALE EAST"
replace enep = 2.36154 if district_name == "YEOVIL"
replace enep = 3.405847 if district_name == "YORK CENTRAL"
replace enep = 2.900047 if district_name == "YORK OUTER"
replace enep = 3.39569 if district_name == "BELFAST EAST"
replace enep = 3.337888 if district_name == "BELFAST NORTH"
replace enep = 3.601564 if district_name == "BELFAST SOUTH"
replace enep = 1.854956 if district_name == "BELFAST WEST"
replace enep = 3.432466 if district_name == "EAST ANTRIM"
replace enep = 4.525525 if district_name == "EAST LONDONDERRY"
replace enep = 2.359054 if district_name == "FERMANAGH AND SOUTH TYRONE"
replace enep = 3.100413 if district_name == "FOYLE"
replace enep = 3.152131 if district_name == "LAGAN VALLEY"
replace enep = 3.038247 if district_name == "MID ULSTER"
replace enep = 3.515764 if district_name == "NEWRY AND ARMAGH"
replace enep = 3.513332 if district_name == "NORTH ANTRIM"
replace enep = 1.959313 if district_name == "NORTH DOWN"
replace enep = 4.108731 if district_name == "SOUTH ANTRIM"
replace enep = 3.011466 if district_name == "SOUTH DOWN"
replace enep = 3.278003 if district_name == "STRANGFORD"
replace enep = 3.862877 if district_name == "UPPER BANN"
replace enep = 3.186058 if district_name == "WEST TYRONE"
replace enep = 3.365471 if district_name == "ABERDEEN NORTH"
replace enep = 3.685297 if district_name == "ABERDEEN SOUTH"
replace enep = 2.450594 if district_name == "AIRDRIE AND SHOTTS"
replace enep = 3.405335 if district_name == "ANGUS"
replace enep = 4.071805 if district_name == "ARGYLL AND BUTE"
replace enep = 3.043598 if district_name == "AYR, CARRICK AND CUMNOCK"
replace enep = 3.354858 if district_name == "BANFF AND BUCHAN"
replace enep = 2.951803 if district_name == "BERWICKSHIRE, ROXBURGH AND SELKIRK"
replace enep = 3.497413 if district_name == "CAITHNESS, SUTHERLAND AND EASTER ROSS"
replace enep = 3.128542 if district_name == "CENTRAL AYRSHIRE"
replace enep = 2.059233 if district_name == "COATBRIDGE, CHRYSTON AND BELLSHILL"
replace enep = 2.498595 if district_name == "CUMBERNAULD, KILSYTH AND KIRKINTILLOCH EAST"
replace enep = 2.995164 if district_name == "DUMFRIES AND GALLOWAY"
replace enep = 3.580426 if district_name == "DUMFRIESSHIRE, CLYDESDALE AND TWEEDDALE"
replace enep = 3.459542 if district_name == "DUNDEE EAST"
replace enep = 2.938673 if district_name == "DUNDEE WEST"
replace enep = 2.83302 if district_name == "DUNFERMLINE AND WEST FIFE"
replace enep = 3.317102 if district_name == "EAST DUNBARTONSHIRE"
replace enep = 2.89443 if district_name == "EAST KILBRIDE, STRATHAVEN AND LESMAHAGOW"
replace enep = 3.424916 if district_name == "EAST LOTHIAN"
replace enep = 2.726826 if district_name == "EAST RENFREWSHIRE"
replace enep = 3.537833 if district_name == "EDINBURGH EAST"
replace enep = 3.481632 if district_name == "EDINBURGH NORTH AND LEITH"
replace enep = 3.45779 if district_name == "EDINBURGH SOUTH"
replace enep = 3.448173 if district_name == "EDINBURGH SOUTH WEST"
replace enep = 3.609994 if district_name == "EDINBURGH WEST"
replace enep = 2.999002 if district_name == "NA H-EILEANAN AN IAR"
replace enep = 3.08398 if district_name == "FALKIRK"
replace enep = 2.983541 if district_name == "GLASGOW CENTRAL"
replace enep = 2.242704 if district_name == "GLASGOW EAST"
replace enep = 3.154714 if district_name == "GLASGOW NORTH"
replace enep = 2.008476 if district_name == "GLASGOW NORTH EAST"
replace enep = 2.844742 if district_name == "GLASGOW NORTH WEST"
replace enep = 2.973161 if district_name == "GLASGOW SOUTH"
replace enep = 2.310146 if district_name == "GLASGOW SOUTH WEST"
replace enep = 2.237186 if district_name == "GLENROTHES"
replace enep = 3.922994 if district_name == "GORDON"
replace enep = 2.657565 if district_name == "INVERCLYDE"
replace enep = 3.727085 if district_name == "INVERNESS, NAIRN, BADENOCH AND STRATHSPEY"
replace enep = 2.710975 if district_name == "KILMARNOCK AND LOUDOUN"
replace enep = 2.199589 if district_name == "KIRKCALDY AND COWDENBEATH"
replace enep = 3.036685 if district_name == "LANARK AND HAMILTON EAST"
replace enep = 2.910814 if district_name == "LINLITHGOW AND EAST FALKIRK"
replace enep = 3.05938 if district_name == "LIVINGSTON"
replace enep = 3.25323 if district_name == "MIDLOTHIAN"
replace enep = 3.618201 if district_name == "MORAY"
replace enep = 2.352369 if district_name == "MOTHERWELL AND WISHAW"
replace enep = 3.061423 if district_name == "NORTH AYRSHIRE AND ARRAN"
replace enep = 3.400378 if district_name == "NORTH EAST FIFE"
replace enep = 3.631783 if district_name == "OCHIL AND SOUTH PERTHSHIRE"
replace enep = 2.372147 if district_name == "ORKNEY AND SHETLAND"
replace enep = 2.77066 if district_name == "PAISLEY AND RENFREWSHIRE NORTH"
replace enep = 2.452458 if district_name == "PAISLEY AND RENFREWSHIRE SOUTH"
replace enep = 3.419913 if district_name == "PERTH AND NORTH PERTHSHIRE"
replace enep = 2.95405 if district_name == "ROSS, SKYE AND LOCHABER"
replace enep = 2.383441 if district_name == "RUTHERGLEN AND HAMILTON WEST"
replace enep = 3.530047 if district_name == "STIRLING"
replace enep = 3.539448 if district_name == "WEST ABERDEENSHIRE AND KINCARDINE"
replace enep = 2.331244 if district_name == "WEST DUNBARTONSHIRE"
replace enep = 4.128353 if district_name == "YNYS MON"
replace enep = 3.186984 if district_name == "DELYN"
replace enep = 3.359104 if district_name == "ALYN AND DEESIDE"
replace enep = 3.669571 if district_name == "WREXHAM"
replace enep = 3.306829 if district_name == "LLANELLI"
replace enep = 3.429012 if district_name == "GOWER"
replace enep = 3.600372 if district_name == "SWANSEA WEST"
replace enep = 3.047014 if district_name == "SWANSEA EAST"
replace enep = 3.034933 if district_name == "ABERAVON"
replace enep = 3.301194 if district_name == "CARDIFF CENTRAL"
replace enep = 3.189866 if district_name == "CARDIFF NORTH"
replace enep = 2.768316 if district_name == "RHONDDA"
replace enep = 3.555745 if district_name == "TORFAEN"
replace enep = 2.946613 if district_name == "MONMOUTH"
replace enep = 3.382447 if district_name == "NEWPORT EAST"
replace enep = 3.278964 if district_name == "NEWPORT WEST"
replace enep = 3.689899 if district_name == "ARFON"
replace enep = 3.879587 if district_name == "ABERCONWY"
replace enep = 3.558142 if district_name == "CLWYD WEST"
replace enep = 3.099241 if district_name == "VALE OF CLWYD"
replace enep = 3.529032 if district_name == "DWYFOR MEIRIONNYDD"
replace enep = 3.606876 if district_name == "CLWYD SOUTH"
replace enep = 3.053881 if district_name == "MONTGOMERYSHIRE"
replace enep = 2.874833 if district_name == "CEREDIGION"
replace enep = 3.222426 if district_name == "PRESELI PEMBROKESHIRE"
replace enep = 3.312212 if district_name == "CARMARTHEN WEST AND SOUTH PEMBROKESHIRE"
replace enep = 3.801756 if district_name == "CARMARTHEN EAST AND DINEFWR"
replace enep = 2.787077 if district_name == "BRECON AND RADNORSHIRE"
replace enep = 3.392431 if district_name == "NEATH"
replace enep = 2.882042 if district_name == "CYNON VALLEY"
replace enep = 3.268873 if district_name == "MERTHYR TYDFIL AND RHYMNEY"
replace enep = 2.829769 if district_name == "BLAENAU GWENT"
replace enep = 3.569102 if district_name == "BRIDGEND"
replace enep = 2.87493 if district_name == "OGMORE"
replace enep = 3.56119 if district_name == "PONTYPRIDD"
replace enep = 3.535854 if district_name == "CAERPHILLY"
replace enep = 3.314575 if district_name == "ISLWYN"
replace enep = 3.220818 if district_name == "VALE OF GLAMORGAN"
replace enep = 3.3922 if district_name == "CARDIFF WEST"
replace enep = 3.519212 if district_name == "CARDIFF SOUTH AND PENARTH"


***************************
** INDEPENDENT VARIABLES **
***************************

* Time

gen surveydate = date(string(ayymmdd,"%8.0f"),"YMD")

format %tdMon_DD,_CCYY surveydate

gen edate = 20100506

gen electiondate = date(string(edate,"%8.0f"),"YMD")

format %tdMon_DD,_CCYY electiondate

gen time = electiondate - surveydate

* Gender

gen male = zq88

recode male 2=0

* Age

gen age = zq89

recode age (-2=.)
recode age (-1=.)

* Education

gen education = zq95_1

recode education -2=. -1=. 6=. 7=5

* Interest for election

gen interest = aq1

recode interest (-1=.)

replace interest = 5 - interest

* Party identification (district)

gen pidstatus_district = .

replace pidstatus_district = 9999 if aq10_1 == -2 & aq10_3 == -2 | aq10_1 == -1 & aq10_3 == -1 | aq10_1 == -2 & aq10_3 == -1 | aq10_1 == -1 & aq10_3 == -2

replace pidstatus_district = 2 if aq10_1 == 1 & aq10_3 == . & pidstatus_district!=9999

replace pidstatus_district = 3 if aq10_1 == constituency_2010 & pidstatus_district!=2 & pidstatus_district!=9999
replace pidstatus_district = 3 if aq10_3 == constituency_2010 & pidstatus_district!=2 & pidstatus_district!=9999

replace pidstatus_district = 1 if aq10_1!=constituency_2010 & aq10_1!=. & pidstatus_district!=2 & pidstatus_district!=3 & pidstatus_district!=9999
replace pidstatus_district = 1 if aq10_3!=constituency_2010 & aq10_3!=. & pidstatus_district!=2 & pidstatus_district!=3 & pidstatus_district!=9999

replace pidstatus_district = . if pidstatus_district == 9999

label define pidstatus 1 "Loser PID" 2 "No PID" 3 "Winner PID"
label values pidstatus_district pidstatus

* Party identification scale (district)

gen pidscale_district = .

replace pidscale_district = 1 if pidstatus_district == 1 & aq10_4 == 1
replace pidscale_district = 2 if pidstatus_district == 1 & aq10_4 == 2
replace pidscale_district = 3 if pidstatus_district == 1 & aq10_4 == 3
replace pidscale_district = 4 if pidstatus_district == 2
replace pidscale_district = 5 if pidstatus_district == 3 & aq10_4 == 3
replace pidscale_district = 6 if pidstatus_district == 3 & aq10_4 == 2
replace pidscale_district = 7 if pidstatus_district == 3 & aq10_4 == 1

label define pidscale 1 "Strong loser PID" 2 "Moderate loser PID" 3 "Weak loser PID" 4 "No PID" 5 "Weak winner PID" 6 "Moderate winner PID" 7 "Strong winner PID" 
label values pidscale_district pidscale

* Party identification (national)

gen pidstatus_whole = .

replace pidstatus_whole = 9999 if aq10_1 == -2 & aq10_3 == -2 | aq10_1 == -1 & aq10_3 == -1 | aq10_1 == -2 & aq10_3 == -1 | aq10_1 == -1 & aq10_3 == -2

replace pidstatus_whole = 2 if aq10_1 == 1 & aq10_3 == . & pidstatus_whole!=9999

replace pidstatus_whole = 3 if aq10_1 == 3 & pidstatus_whole!=2 & pidstatus_whole!=9999
replace pidstatus_whole = 3 if aq10_3 == 3 & pidstatus_whole!=2 & pidstatus_whole!=9999

replace pidstatus_whole = 1 if aq10_1!=3 & aq10_1!=. & pidstatus_whole!=2 & pidstatus_whole!=3 & pidstatus_whole!=9999
replace pidstatus_whole = 1 if aq10_3!=3 & aq10_3!=. & pidstatus_whole!=2 & pidstatus_whole!=3 & pidstatus_whole!=9999

replace pidstatus_whole = . if pidstatus_whole == 9999

label values pidstatus_whole pidstatus

* Party identification scale (national)

gen pidscale_whole = .

replace pidscale_whole = 1 if pidstatus_whole == 1 & aq10_4 == 1
replace pidscale_whole = 2 if pidstatus_whole == 1 & aq10_4 == 2
replace pidscale_whole = 3 if pidstatus_whole == 1 & aq10_4 == 3
replace pidscale_whole = 4 if pidstatus_whole == 2
replace pidscale_whole = 5 if pidstatus_whole == 3 & aq10_4 == 3
replace pidscale_whole = 6 if pidstatus_whole == 3 & aq10_4 == 2
replace pidscale_whole = 7 if pidstatus_whole == 3 & aq10_4 == 1

label values pidscale_whole pidscale

* Newspaper

gen press = bq80_1

recode press -2=. -1=. 2=0

* TV

gen tv = bq81

recode tv -2=. -1=.

replace tv = tv - 1

* Internet news

gen internet = cq11

recode internet -3=.

replace internet = 4 - internet

* News attentiveness

egen news = rowmax(press tv internet)

* Political discussion with spouse or partner

gen discussion_partner = cq26_1

recode discussion_partner -3=. 5=4

replace discussion_partner = 4 - discussion_partner

gen discussion_partner_3pts = discussion_partner
replace discussion_partner_3pts = 0 if discussion_partner == 1
replace discussion_partner_3pts = 1 if discussion_partner == 2
replace discussion_partner_3pts = 2 if discussion_partner == 3

* Political discussion with other family members

gen discussion_family = cq26_2

recode discussion_family -3=. 5=4

replace discussion_family = 4 - discussion_family

gen discussion_family_3pts = discussion_family
replace discussion_family_3pts = 0 if discussion_family == 1
replace discussion_family_3pts = 1 if discussion_family == 2
replace discussion_family_3pts = 2 if discussion_family == 3

* Political discussion with friends

gen discussion_friends = cq26_3

recode discussion_friends -3=. 5=4

replace discussion_friends = 4 - discussion_friends

gen discussion_friends_3pts = discussion_friends
replace discussion_friends_3pts = 0 if discussion_friends == 1
replace discussion_friends_3pts = 1 if discussion_friends == 2
replace discussion_friends_3pts = 2 if discussion_friends == 3

* Political discussion with neighbours

gen discussion_neighbours = cq26_4

recode discussion_neighbours -3=. 5=4

replace discussion_neighbours = 4 - discussion_neighbours

gen discussion_neighbours_3pts = discussion_neighbours
replace discussion_neighbours_3pts = 0 if discussion_neighbours == 1
replace discussion_neighbours_3pts = 1 if discussion_neighbours == 2
replace discussion_neighbours_3pts = 2 if discussion_neighbours == 3

* Political discussion with fellow workers

gen discussion_coworkers = cq26_5

recode discussion_coworkers -3=. 5=4

replace discussion_coworkers = 4 - discussion_coworkers

gen discussion_coworkers_3pts = discussion_coworkers
replace discussion_coworkers_3pts = 0 if discussion_coworkers == 1
replace discussion_coworkers_3pts = 1 if discussion_coworkers == 2
replace discussion_coworkers_3pts = 2 if discussion_coworkers == 3

* Political discussion

gen discussion = discussion_partner + discussion_family + discussion_friends + discussion_neighbours + discussion_coworkers

egen discussion_3pts = rowmax(discussion_partner_3pts discussion_family_3pts discussion_friends_3pts discussion_neighbours_3pts discussion_coworkers_3pts)

* Spouse or partner party support

gen disagreement_partner = cq27_1

recode disagreement_partner -3=. -1=. 5=1

replace disagreement_partner = disagreement_partner - 1

* Family members party support

gen disagreement_family = cq27_2

recode disagreement_family -3=. -1=. 5=1

replace disagreement_family = disagreement_family - 1

* Friends party support

gen disagreement_friends = cq27_3

recode disagreement_friends -3=. -1=. 5=1

replace disagreement_friends = disagreement_friends - 1

* Neighbours party support

gen disagreement_neighbours = cq27_4

recode disagreement_neighbours -3=. -1=. 5=1

replace disagreement_neighbours = disagreement_neighbours - 1

* Fellow workers party support

gen disagreement_coworkers = cq27_5

recode disagreement_coworkers -3=. -1=. 5=1

replace disagreement_coworkers = disagreement_coworkers - 1

* Disagreement

gen disagreement = disagreement_partner + disagreement_family + disagreement_friends + disagreement_neighbours + disagreement_coworkers

egen disagreement_3pts = rowmax(disagreement_partner disagreement_family disagreement_friends disagreement_neighbours disagreement_coworkers)

* Talk to people in neighbourhood

gen talk_neighbourhood = cq32_4

recode talk_neighbourhood (-3=.)

replace talk_neighbourhood = 5 - talk_neighbourhood

* Years lived in neighbourhood

gen years_neighbourhood = cq30

recode years_neighbourhood (-3=.)

* Care about outcome

gen care_whole = cq1

recode care_whole -3=. -1. 2=0

* Polling stations close at 10.00pm on election day - Correct answer (true) = 1, Incorrect answer = 0

gen stations = bq79_1

recode stations -1=0 2=0

* The Liberal Democrats favour a system of proportional representation for Westminster elections - Correct answer (true) = 1, Incorrect answer = 0

gen libdempr = bq79_2

recode libdempr -1=0 2=0

* The minimum voting age is 16 - Correct answer (false) = 1, Incorrect answer = 0

gen votingage = bq79_3

recode votingage -1=0 1=0 2=1

* The standard rate of income tax payable is 26p in the pound - Correct answer (false) = 1, Incorrect answer = 0

gen incometax = bq79_4

recode incometax -1=0 1=0 2=1

* The Chancellor of the Exchequer is responsible for setting interest rates in the UK - Correct answer (false) = 1, Incorrect answer = 0

gen interestrates = bq79_5

recode interestrates -1=0 1=0 2=1

* Labour promises withdrawing all British troops from Afghanistan by the end of 2010 - Correct answer (false) = 1, Incorrect answer = 0

gen troops = bq79_6

recode troops -1=0 1=0 2=1

* The Conservative Party favours reducing the budget deficit without cutting funding for the National Health Service - Correct answer (true) = 1, Incorrect answer = 0

gen deficit = bq79_7

recode deficit -1=0 2=0

* Any registered voter can obtain a postal vote if they want one - by contacting their local council and asking for a postal vote - Correct answer (true) = 1, Incorrect answer = 0

gen postalvote = bq79_8

recode postalvote -1=0 2=0

* Political knowledge index

gen knowledge = stations + libdempr + votingage + incometax + interestrates + troops + deficit + postalvote


*********************************
** DISTRICT-LEVEL EXPECTATIONS ** 
*********************************

gen lab_chance_district = aq12_1 // Labour candidate's probability of winning in district
gen con_chance_district = aq12_2 // Conservative candidate's probability of winning in district
gen ld_chance_district = aq12_3 // Liberal Democrat candidate's probability of winning in district
gen snp_chance_district = aq12_4 // SNP candidate's probability of winning in district
gen pc_chance_district = aq12_5 // PC candidate's probability of winning in district

* Generate variable identifying incomplete answers (PC in Wales only, SNP in Scotland only)

gen complete_district_england = 0 if lab_chance_district == . & region == 1 | con_chance_district == . & region == 1 | ld_chance_district == . & region == 1
replace complete_district_england = 1 if lab_chance_district!=. & con_chance_district!=. & ld_chance_district!=. & region == 1

gen complete_district_scotland = 0 if lab_chance_district == . & region == 2 | con_chance_district == . & region == 2 | ld_chance_district == . & region == 2 | snp_chance_district == . & region == 2
replace complete_district_scotland = 1 if lab_chance_district!=. & con_chance_district!=. & ld_chance_district!=. & snp_chance_district!=. & region == 2

gen complete_district_wales = 0 if lab_chance_district == . & region == 3 | con_chance_district == . & region == 3 | ld_chance_district == . & region == 3 | snp_chance_district == . & region == 3 | pc_chance_district == . & region == 3
replace complete_district_wales = 1 if lab_chance_district!=. & con_chance_district!=. & ld_chance_district!=. & snp_chance_district!=. & pc_chance_district!=. & region == 3

gen complete_district = max(complete_district_england,complete_district_wales,complete_district_scotland)

* Generate value of 1 if the expectation for one candidate is higher or equal to the expectations for at least one other candidate (England)

gen lab_win_england = 1 if lab_chance_district >= con_chance_district & lab_chance_district >= ld_chance_district & region == 1 & complete_district_england == 1

gen con_win_england = 1 if con_chance_district >= lab_chance_district & con_chance_district >= ld_chance_district & region == 1 & complete_district_england == 1

gen ld_win_england = 1 if ld_chance_district >= lab_chance_district & ld_chance_district >= con_chance_district & region == 1 & complete_district_england == 1

gen oth_win_england = 1 if lab_chance_district == 0 & con_chance_district == 0 & ld_chance_district == 0 & region == 1 & complete_district_england == 1

* Generate value of 1 if the expectation for one candidate is higher or equal to the expectations for at least one other candidate (Scotland)

gen lab_win_scotland = 1 if lab_chance_district >= con_chance_district & lab_chance_district >= ld_chance_district & lab_chance_district >= snp_chance_district & region == 2 & complete_district_scotland == 1

gen con_win_scotland = 1 if con_chance_district >= lab_chance_district & con_chance_district >= ld_chance_district & con_chance_district >= snp_chance_district & region == 2 & complete_district_scotland == 1

gen ld_win_scotland = 1 if ld_chance_district >= lab_chance_district & ld_chance_district >= con_chance_district & ld_chance_district >= snp_chance_district & region == 2 & complete_district_scotland == 1

gen snp_win_scotland = 1 if snp_chance_district >= lab_chance_district & snp_chance_district >= con_chance_district & snp_chance_district >= ld_chance_district & region == 2 & complete_district_scotland == 1

gen oth_win_scotland = 1 if lab_chance_district == 0 & con_chance_district == 0 & ld_chance_district == 0 & snp_chance_district == 0 & region == 2 & complete_district_scotland == 1

* Generate value of 1 if the expectation for one candidate is higher or equal to the expectations for at least one other candidate (Wales)

gen lab_whole_wales = 1 if lab_chance_district >= con_chance_district & lab_chance_district >= ld_chance_district & lab_chance_district >= pc_chance_district & region == 3 & complete_district_wales == 1

gen con_whole_wales = 1 if con_chance_district >= lab_chance_district & con_chance_district >= ld_chance_district & con_chance_district >= pc_chance_district & region == 3 & complete_district_wales == 1

gen ld_whole_wales = 1 if ld_chance_district >= lab_chance_district & ld_chance_district >= con_chance_district & ld_chance_district >= pc_chance_district & region == 3 & complete_district_wales == 1

gen pc_whole_wales = 1 if pc_chance_district >= lab_chance_district & pc_chance_district >= con_chance_district & pc_chance_district >= ld_chance_district & region == 3 & complete_district_wales == 1

gen oth_whole_wales = 1 if lab_chance_district == 0 & con_chance_district == 0 & ld_chance_district == 0 & snp_chance_district == 0 & pc_chance_district == 0 & region == 3 & complete_district_wales == 1

* Combine

gen lab_district = max(lab_win_england,lab_win_scotland,lab_whole_wales) if complete_district == 1
gen con_district = max(con_win_england,con_win_scotland,con_whole_wales) if complete_district == 1
gen ld_district = max(ld_win_england,ld_win_scotland,ld_whole_wales) if complete_district == 1
gen snp_district = snp_win_scotland if complete_district == 1
gen pc_district = pc_whole_wales if complete_district == 1
gen oth_district = max(oth_win_england,oth_win_scotland,oth_whole_wales) if complete_district == 1

replace lab_district = . if oth_district == 1 & complete_district == 1
replace con_district = . if oth_district == 1 & complete_district == 1
replace ld_district = . if oth_district == 1 & complete_district == 1
replace snp_district = . if oth_district == 1 & complete_district == 1
replace pc_district = . if oth_district == 1 & complete_district == 1

* Generate variable for ambiguous forecasts

gen ambiguous_district = .

replace ambiguous_district = 99 if lab_district == con_district & lab_district!=. & complete_district == 1 | lab_district == ld_district & lab_district!=. & complete_district == 1 | lab_district == snp_district & lab_district!=. & complete_district == 1 | lab_district == pc_district & lab_district!=. & complete_district == 1

replace ambiguous_district = 99 if con_district == lab_district & con_district!=. & complete_district == 1 | con_district == ld_district & con_district!=. & complete_district == 1 | con_district == snp_district & con_district!=. & complete_district == 1 | con_district == pc_district & con_district!=. & complete_district == 1

replace ambiguous_district = 99 if ld_district == lab_district & ld_district!=. & complete_district == 1 | ld_district == con_district & ld_district!=. & complete_district == 1 | ld_district == snp_district & ld_district!=. & complete_district == 1 | ld_district == pc_district & ld_district!=. & complete_district == 1

replace ambiguous_district = 99 if snp_district == lab_district & snp_district!=. & complete_district == 1 | snp_district == con_district & snp_district!=. & complete_district == 1 | snp_district == ld_district & snp_district!=. & complete_district == 1 | snp_district == pc_district & snp_district!=. & complete_district == 1

replace ambiguous_district = 99 if pc_district == lab_district & pc_district!=. & complete_district == 1 | pc_district == con_district & pc_district!=. & complete_district == 1 | pc_district == ld_district & pc_district!=. & complete_district == 1 | pc_district == snp_district & pc_district!=. & complete_district == 1

* Generate value of 0 for lower expectations

replace lab_district = 0 if lab_district!=1 & complete_district == 1
replace con_district = 0 if con_district!=1 & complete_district == 1
replace ld_district = 0 if ld_district!=1 & complete_district == 1
replace snp_district = 0 if snp_district!=1 & complete_district == 1
replace pc_district = 0 if pc_district!=1 & complete_district == 1
replace oth_district = 0 if oth_district!=1 & complete_district == 1

* Forecasts (2 = Labour, 3 = Conservative, 4 = Liberal Democrat, 5 = SNP, 6 = PC, 7 = Green, 8 = UKIP, 9 = BNP, 10 = other, 99 = ambiguous)

gen forecast_district = .

replace forecast_district = 2 if lab_district == 1 & complete_district == 1
replace forecast_district = 3 if con_district == 1 & complete_district == 1
replace forecast_district = 4 if ld_district == 1 & complete_district == 1
replace forecast_district = 5 if snp_district == 1 & complete_district == 1
replace forecast_district = 6 if pc_district == 1 & complete_district == 1
replace forecast_district = 10 if oth_district == 1 & complete_district == 1
replace forecast_district = 99 if ambiguous_district == 99 & complete_district == 1

* Identify correct and ambiguous forecasts

gen correct_district = 0 if forecast_district!=constituency_2010 & forecast_district!=99 & constituency_2010!=. & complete_district == 1
replace correct_district = 1 if forecast_district == constituency_2010 & forecast_district!=99 & constituency_2010!=. & complete_district == 1

replace correct_district = 0 if forecast_district == 99 & lab_district!=1 & constituency_2010 == 2 & complete_district == 1
replace correct_district = 0 if forecast_district == 99 & con_district!=1 & constituency_2010 == 3 & complete_district == 1
replace correct_district = 0 if forecast_district == 99 & ld_district!=1 & constituency_2010 == 4 & complete_district == 1
replace correct_district = 0 if forecast_district == 99 & snp_district!=1 & constituency_2010 == 5 & complete_district == 1
replace correct_district = 0 if forecast_district == 99 & pc_district!=1 & constituency_2010 == 6 & complete_district == 1
replace correct_district = 0 if forecast_district == 99 & oth_district!=1 & constituency_2010 == 10 & complete_district == 1

replace correct_district = 99 if correct_district == . & constituency_2010!=. & complete_district == 1

* Generate dichotomous variable (treat ambiguous forecasts as incorrect)

gen correct_district_d = correct_district

replace correct_district_d = 0 if correct_district_d == 99
replace correct_district_d = 1 if correct_district_d == 1


*********************************
** NATIONAL-LEVEL EXPECTATIONS ** 
*********************************

gen lab_chance_whole = aq13_1 // Labour party's probability of winning the election
gen con_chance_whole = aq13_2 // Conservative party's probability of winning the election
gen ld_chance_whole = aq13_3 // Liberal Democrats' probability of winning the election

* Generate variable identifying incomplete answers

gen complete_whole = 0 if lab_chance_whole == . | con_chance_whole == . | ld_chance_whole == .
replace complete_whole = 1 if lab_chance_whole!=. & con_chance_whole!=. & ld_chance_whole!=.

* Generate value of 1 if the expectation for one party is higher or equal to the expectations for at least one other party

gen lab_whole = 1 if lab_chance_whole >= con_chance_whole & lab_chance_whole >= ld_chance_whole & complete_whole == 1

gen con_whole = 1 if con_chance_whole >= lab_chance_whole & con_chance_whole >= ld_chance_whole & complete_whole == 1

gen ld_whole = 1 if ld_chance_whole >= lab_chance_whole & ld_chance_whole >= con_chance_whole & complete_whole == 1

gen oth_whole = 1 if lab_chance_whole == 0 & con_chance_whole == 0 & ld_chance_whole == 0 & complete_whole == 1

replace lab_whole = . if oth_whole == 1 & complete_whole == 1
replace con_whole = . if oth_whole == 1 & complete_whole == 1
replace ld_whole = . if oth_whole == 1 & complete_whole == 1

* Generate variable for ambiguous forecasts

gen ambiguous_whole = .

replace ambiguous_whole = 99 if lab_whole == con_whole & lab_whole!=. & complete_whole == 1 | lab_whole == ld_whole & lab_whole!=. & complete_whole == 1

replace ambiguous_whole = 99 if con_whole == lab_whole & con_whole!=. & complete_whole == 1 | con_whole == ld_whole & con_whole!=. & complete_whole == 1

replace ambiguous_whole = 99 if ld_whole == lab_whole & ld_whole!=. & complete_whole == 1 | ld_whole == con_whole & ld_whole!=. & complete_whole == 1

* Generate value of 0 for lower expectations

replace lab_whole = 0 if lab_whole!=1 & lab_whole!=. & complete_whole == 1
replace con_whole = 0 if con_whole!=1 & con_whole!=. & complete_whole == 1
replace ld_whole = 0 if ld_whole!=1 & ld_whole!=. & complete_whole == 1
replace oth_whole = 0 if oth_whole!=1 & oth_whole!=. & complete_whole == 1

* Forecasts (2 = Labour, 3 = Conservative, 4 = Liberal Democrat, 10 = other, 99 = ambiguous)

gen forecast_whole = .

replace forecast_whole = 2 if lab_whole == 1 & complete_whole == 1
replace forecast_whole = 3 if con_whole == 1 & complete_whole == 1 
replace forecast_whole = 4 if ld_whole == 1 & complete_whole == 1
replace forecast_whole = 10 if oth_whole == 1 & complete_whole == 1
replace forecast_whole = 99 if ambiguous_whole == 99 & complete_whole == 1

* Identify correct and ambiguous forecasts

gen correct_whole = 0 if forecast_whole!=3 & forecast_whole!=99 & forecast_whole!=. & complete_whole == 1
replace correct_whole = 1 if forecast_whole == 3 & forecast_whole!=99 & forecast_whole!=. & complete_whole == 1
replace correct_whole = 99 if forecast_whole == 99 & complete_whole == 1

* Generate dichotomous variable (treat ambiguous forecasts as incorrect)

gen correct_whole_d = correct_whole

replace correct_whole_d = 0 if correct_whole_d == 99
replace correct_whole_d = 1 if correct_whole_d == 1


**********
** SAVE **
**********

save "gb2010_bes.dta", replace


*******************
** MAIN ANALYSES **
*******************

* Regression analysis and percentage of correct and incorrect forecasts (national)

logistic correct_whole_d discussion disagreement pidscale_whole interest news knowledge i.care_whole age i.male education time
estimates table, star(.05 .01 .001)

tab correct_whole_d if e(sample) == 1

* Regression analysis and percentage of correct and incorrect forecasts (district)

melogit correct_district_d discussion disagreement pidscale_district interest news knowledge age i.male education time enep || district_name: , or
estimates table, star(.05 .01 .001)

tab correct_district_d if e(sample) == 1


************************
** SUMMARY STATISTICS **
************************

label variable correct_whole_d "Election winner (DV)"
label variable correct_district_d "District winner (DV)"
label variable discussion "Discussion"
label variable disagreement "Disagreement"
label variable pidscale_whole "National PID"
label variable pidscale_district "District PID"
label variable age "Age"
label variable male "Gender (male = 1)"
label variable education "Education"
label variable interest "Interest"
label variable news "News attentiveness"
label variable care_whole "Caring about outcome"
label variable knowledge "Political knowledge"
label variable time "Time of interview"
label variable enep "ENEP"
label variable margin "Margin"

quietly logistic correct_whole_d discussion disagreement pidscale_whole interest news knowledge i.care_whole age i.male education time

estpost tabstat correct_whole_d discussion disagreement pidscale_whole interest news knowledge care_whole age male education time if e(sample) == 1, statistics(n mean p50 sd min max) columns(statistics)

esttab using "gb2010_bes_summary_national.tex", substitute("\begin{table}[htbp]" "\begin{table}[H]") cells("count(label(N) fmt(%9.0fc)) mean(fmt(%5.1f) label(Mean)) p50(fmt(%5.1f) label(Median)) sd(fmt(%5.1f) label(Std. dev.)) min(fmt(%5.1f) label(Min)) max(fmt(%5.1f) label(Max))") label width(\textwidth) nomtitle nonumber noobs booktabs title("Summary statistics -- 2010 British general election (BES), national level") replace

eststo clear

quietly melogit correct_district_d discussion disagreement pidscale_district interest news knowledge age i.male education time enep || district_name: , or

estpost tabstat correct_district_d discussion disagreement pidscale_district interest news knowledge age male education time if e(sample) == 1, statistics(n mean p50 sd min max) columns(statistics)

esttab using "gb2010_bes_summary_district.tex", substitute("\begin{table}[htbp]" "\begin{table}[H]") cells("count(label(N) fmt(%9.0fc)) mean(fmt(%5.1f) label(Mean)) p50(fmt(%5.1f) label(Median)) sd(fmt(%5.1f) label(Std. dev.)) min(fmt(%5.1f) label(Min)) max(fmt(%5.1f) label(Max))") label width(\textwidth) nomtitle nonumber noobs booktabs title("Summary statistics -- 2010 British general election (BES), district level") replace

eststo clear

log close